Ansible lab Setup for local testing

  • Download and Install Oracle VM Virtual box: It helps us to run multiple Operating systems on the same machine. From here you will be able to download it https://www.virtualbox.org/wiki/Downloads
  • Now create 3 Ubuntu machines on the Virtual box. One will be treated as an Ansible server and the other two will be Ansible clients. Follow this link to install Ubuntu on Virtual box How to install Ubuntu in Virtual box
  • We can name them as :
    Ansible Server
    Ansible client 1 ( Username: test Password: Test@123 )
    Ansible client 2 ( Username: test Password: Test@456 )
    Check the snapshot below
ansible server and client
  • Install Ansible on Ansible Server machine ( No need to install Ansible on client machines )
>> sudo apt-get update
>> sudo apt-get install ansible
  • Install sshpass on Ansible Server. The sshpass will help Ansible to ssh the client machines using password instead of public-private key pair.
>> sudo apt-get install sshpass
  • We also have to configure the password-based SSH authentication on Ansible Server for that we have to open the /etc/ssh/ssh_config file and update this line as below
PasswordAuthentication yes
  • Install Openssh server on Ansible client 1 and Ansible client 2
>> sudo apt-get install openssh-server
  • We will check the IP address of the client machines
>> ifconfig 

ifconfig command will print the IP address. If ifconfig is not printing IP address then install net-tools package then check Ip address

>> sudo apt-get install net-tools
  • The IP address of Ansible client 1 on my system is 192.168.1.6
  • The IP address of Ansible client 2 on my system is 192.168.1.8
  • Open the hosts file on Ansible Server
>> /etc/ansible/hosts
  • Update the hosts file with the Ansible client’s address. My hosts file is as below
192.168.1.6 ansible_ssh_pass=Test@123 ansible_ssh_user=test
192.168.1.8 ansible_ssh_pass=Test@456 ansible_ssh_user=test
  • Ansible will read the above hosts file by default.
  • Now we will ping the Ansible clients from Ansible Server using the ansible module ping
>> ansible all -m ping

all - It will look for all the IP addresses in the hosts file 

Output :

92.168.1.6 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

192.168.1.8 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

This is the Ansible lab Setup for local testing. We can learn and practice different Ansible concepts on your system by making use of this Ansible lab setup.

I hope you found this article interesting and valuable. Please share this article with your friends and help me grow. If you are having any concerns or questions about this article please comment below. If you want to get in touch with me please visit the Contact Me page and send an email.

Leave a Comment