Ansible: Configuring Ansible Server — Client Infrastructure

Share At:


Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration.

Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.


  1. In this demonstration, we will be using centos-07. Please go through the Ansible documentation for supported OS platforms.
  2. We will be using 3 machines for our lab: 1 ansible workstation and 2 ansible clients with the below IP details:

Note: Ansible workstation would be our ansible server.

3. For all the servers — memory should be at least 2 GB and there should be at least 2 core cpu.

4. Ansible workstation and client servers should be able to communicate with each other over ssh (port 22).

Configuring Ansible Workstation:

  1. Set the hostname of the ansible workstation with “hostnamectl” command:

2. Update the /etc/hosts with all server details(Ansible workstation as well as ansible clients):

3. Install the “epel-release” repository. This will help us with installing “Pip” which is a python installer:

4. Validate if “epel-release” repository has been enabled:

5. Now use “yum package manager” to install the “pip” package:

6. Now validate the “pip” version which we have just installed:

7. Since the pip version is “low”, we need to upgrade it. Use “pip install — upgrade pip” to upgrade the pip:

8. Now validate the pip version by using the “pip — version” command:

9. Now install “ansible” by using the “pip install ansible” command:

10. Validate the ansible version :

11. Now create the “/etc/ansible” directory. Also, create our ansible inventory file called “/etc/ansible/hosts” file with details of all the ansible managed servers along with their category. This should look like below:

12. The command “ansible all — list-hosts” should show you all the IP’s of ansible managed hosts including “ansible workstation”:

13. Now we will have to establish password less authentication between “Ansible Workstation” and “client servers”.

For this on Ansible workstation, “su” to “vagrant” user since it’s not advisable to run ansible command with “root” user which is superuser. Now use “ssh-keygen” command to create Public/Private key pair like below:

Note: When you build a machine using Vagrant, the “vagrant” user gets created by default. This user has “Sudo” privilege”

14. Copy the public key to remote client servers using “ssh-copy-id” command:

15. Validate if the passwordless authentication is working between ansible workstation and clients.

We are all set. Our Ansible server-client Infrastructure has been set up.

Now Since we have set up the Infrastructure, let’s test how it is working.

  1. The below command will show you the fqdn of our ansible client — “webserver”.

(Note: Ansible achieves it by gathering “Facts” from client-server)

2. Below command will show the “uptime” of another client called — applicationserver.

3. Below command will copy /etc/hosts file in /tmp directory of client-server called “applicationserver”:

Note: We are using the “copy” module here.

Now validate if the file has been copied on the destination server. The below output confirms that the file has been copied:

4. Below command will delete /tmp/hosts file from applicationserver. We are using the “file” module of ansible:

Now validate that file has been deleted. Below output shows that the file has been actually deleted from the destination server:

This concludes our Tutorial of “Configuring Ansible Server — Client Infrastructure”.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Back To Top

Contact Us