CentOS 7 configuration using Ansible



Ansible is an open-source software provisioning, configuration management, and application-deployment tool. 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 doesn’t require any worker nodes to be running on the other nodes. What it does is that it connect to the nodes and push out small programs, called “Ansible Modules”. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules (over SSH by default) and removes them when finished. Details can be found on this link.

This article gives the newbies a head start about configuring a Linux server(CentOS7) using Ansible. There are other tools that also serve the same purpose, comparison between them can be found on this link.


In this tutorial, I am using a Ubuntu server to install some utilities and Jenkins server on CentOS 7 server.
  1. Install ansible on the Ubuntu server:
$ sudo apt-get update
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible -y

2. Generate SSH key using the command given below:

$ ssh-keygen -t rsa

It will generate a public and private key in ~/.ssh/ folder. The public key will be used later.

3. Create a CentOS 7 server on any cloud. In this tutorial, I am using a CentOS 7 based VM on Google Cloud because it provides 300 free credits.

4. Once the server is in running state. Add your ssh pub key generated on Ubuntu VM to CentOS 7 VM. SSH pub key can be found in this file~/.ssh/id_ras.pub.

5. When the ansible gets installed it creates a hosts file(/etc/ansible/host) that holds the configuration for the nodes. Add the IP of the CentOS 7 based server in this file in this format:


6. Ping the nodes to verify they are accessible by ansible:

ansible -m ping all

It will output a message regarding the nodes' accessibility.

7. Once nodes are accessible, create an inventory file(with .yml extension) that holds the information about the packages that will be installed on the nodes

In the inventory file, tasks are added and each task performs an operation on the server. In these tasks following operations are being performed:

  • creates a Linux user named devops.
  • install a few packages.
  • add a docker repository.
  • install docker.
  • start docker service.
  • create a docker group.
  • add devops user to the docker group, so that sudo is not used for performing docker operations.
  • install docker-compose.
  • make the docker-compose utility’s file executable.

8. Run ansible-playbook using the command given below:

ansible-playbook <playbook-name> -v

-v specifies the verbosity level.

9. ssh the server and verify packages are installed successfully. If you have multiple servers, verify each node one by one:

ssh <username>@NODE_1_IP_PLACEHOLDER

10. I have created a video of the above steps being performed. Check it out.

Final Thoughts

This story is based on my learning, if anything can be improved do let me know.

DevSecOps Engineer https://irtizaali.com/