fbpx

If you do not have Ansible already installed then you can install using the command below. (All commands and files used are available for download at the end of the guide)

yum install ansible -y

  1.  Create an Ansible directory in your home folder and navigate inside it. All files reside in this directory and all commands are run from here.

2. Use vim ansible.cfg to create the ansible configuration file and populate the file with the following. (You can download the code and the file at the end of this guide)

ansible-cfg

The above is a simple configuration file for ansible in which the default section defines the host_inventory file that will have the list of hosts and what user to connect as to the remote nodes. The privilege_escalation indicates that its is a ssh-key based login with no password and commands are run with root privileges.

3. Now we will create the inventory file which is a simple file with the names of hosts. You can use your favorite editor to create this file. I am using vim host_inventory. This inventory files consists of 12 hosts, devhost01-devhost10, devhosta and devhostb (This file is available to download at the end of the guide.) 

ansible-host-inventory

4. We will now create a simple ansible playbook to install the php and mariadb packages on all the hosts in the listed inventory. Watch the indentation as YAML is “indent-sensitive”. (You can download this file at the end of the guide)

install-packages-yaml

This playbook installs php and mariadb packages on all hosts defined in the inventory file

5. Run the playbook using the command ansible-playbook install_packages.yml

run-ansible-packages

If you have new hosts to add, simply go to the inventory file, add the hosts and run the playbook again. If you need to add packages like httpd then go to the install_packages.yml file and add the package name and run the playbook again. You can run the playbook any number of times since Ansible is a desired state engine, which means that if the packages are not present then it will install the packages and if they are present then it will just skip those making package installation a breeze for system admins regardless of the number of systems.

Stay updated about advances in IT

Stay updated about advances in IT

Join our mailing list to receive curated content about advances in IT for more informed IT decisions. These are not more than three or four a month.

You are all set to receive the latest IT news!

×