In this article we will discuss automation of software installation and configuration using ansible. This article is focused on ansible, how to achieve automated installation & configuration of software using ansible. So, if you are interested to leverage the power of ansible to automate some of your manual task then this article will add some value to you.
A brief intro about ansible, it is one of the most powerful automation tool available in the market. It is an open source tool. If you want to get a quick high level understanding of ansible then head over to the below article.
If you want to learn Ansible basics then please check out the below course from KodeKloud which offers one of the best learning material in DevOps world.
Link of Training Course: Ansible for absolute beginners
Note: The above links are affiliate links, if you enroll this course using the above link, then it would help us to get some monetary benefit from KodeKloud. It won’t cost you anything.
Tools like ansible will help you a lot to automate task like software installation and configuration. Generally, you should be able to automate any software installation & its configuration using ansible. By software installation we mean installation of any software which are used by the applications. It could be dependency software, database software, network related software etc.
For example, a Java based application needs below dependency software –
- Web Server – JBoss EAP
We can easily automate the installation of these pieces of software using ansible.
Speaking about advantages of using ansible for automation is, once you develop the ansible playbooks, you can reuse them which brings down our effort and saves time. For example, if you want to install Java & JBoss EAP on 10 machine then that automated solution would be very helpful.
To understand this tutorial, you need the below:
- Hands-on knowledge on ansible – basic/intermediate level.
- Knowledge on manual software installation – basically you need to know the steps to manually install the software which you want to automate using ansible.
- Two Linux machine – one machine will work as ansible host (ansible controller) and another one will work as target machine on which ansible will perform the task. For example, VM-1 will work as ansible host and VM-2 will work as target machine.
You can take Windows machine also as a target machine, but for Windows machine you need to pass different parameters for connection. You can refer below article to configure Windows machine as target machine.
- Ansible should be installed properly in one of the VM-1.
- On the Linux target machine (VM-2) you need a non-root user with sudo privileges. In case of Windows machine, one user is needed which has administrative privileges.
- On the network level ansible host & target machine should be able to communicate. In case of Linux target machine port 22 should be open between them and in case of windows target machine port 5985/5986 should be open between them.
Step 1 – Gather the manual steps to install the software
Before we start automating any software installation the first step is we should have the step-by-step guide to install that software manually.
For example, if you want to automate the installation of Java, then you need to have the manual installation steps of Java.
Step 2 – Identify each task in the manual steps
Once we have the manual steps, try to identify the tasks.
For example, in case of java installation on Linux below are the major task –
- Downloading the binaries
- Unzipping downloaded zip files
- Updating /etc/profile file with JAVA_HOME.
This is just an example, for any such software you need to identify the tasks.
Step 3 – Identify ansible module for each task
Once you identified the tasks in step 2, now you need to identify ansible module for each of the task. Ansible modules have been developed to perform a certain task. For almost all task ansible has a module, which is a great thing.
In step 2, we have discussed the major task for Java installation. Below are the ansible modules which can be used for each of the task.
Ansible Module Name
|Downloading the binaries||get_url module|
|Unzipping downloaded zip files||unarchive module|
Again repeating, here for example purpose we are considering Java installation, you can consider any such software and follow the same steps.
Step 4 – Create a playbook & inventory file
Ansible playbooks are YAML file where we need to mention the tasks which you want ansible to perform on the target machine. Once you are done with step 2 & 3, you need to create a playbook (YAML file).
With the playbook you also need to create an inventory file where you need to put all the details like IP, credential of the target machine. And you need to pass this inventory file while executing the playbook so that ansible can use the information in inventory file to connect with the target machine.
For example, ansible playbook for automating java installation can be found on the below article –
Step 5 – Execute the playbook (YAML file)
If you are done with the step 5, in the next step you need to execute the playbook. Below is the command you can use.
ansible-playbook install-playbook.yml -i inventory.txt -vv
- install install-playbook.yml – it is an example playbook name. You need to replace it with your own playbook name.
- inventory.txt – it is the inventory file where you need to put details about target machine.
“-vv” is added for verbose output.
In the step 4 if we have written the playbook correctly, this step should be successful. If you get any error while executing the playbook, then please read the logs and try to figure out where is the issue. If you are not able to find the solution of the issue then you might take some help from Google, there is a good community support for ansible.
Step 6 – Verify the installation (Optional)
If you are done with step 5 successfully, then in the next step you may verify the installation by logging into the target machine.
When you are initial stage of developing the ansible playbook, in that case you need to log into the target machine and verify the installation.
Another option is adding this verification step at the end of your playbook. So, this will atomically execute the verification steps and print the output in the stdout. And then by checking logs in stdout you can know whether installation is successful or not.
If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.
- Kubernetes Series: Part 1 – Introduction to Kubernetes | Background of Kubernetes
- Kubernetes Series: Part 2 – Components of Kubernetes cluster | Kubernetes cluster in detail
- Kubernetes Series: Part 3 – What is Minikube and How to create a Kubernetes cluster (on Linux) using Minikube?
- Introduction to Ansible | High Level Understanding of Ansible
- Basics of automation using Ansible | Automate any task
- Automation of Java installation – using Ansible
- Automation of JBoss EAP installation – using ansible
- Jenkins Pipeline as code – High level information
- Jenkins pipeline script to build Java application and push artifacts into repository
- Jenkins pipeline script to build & deploy application on web server
- What is End-to-End Monitoring of any web application, and Why do we need it?
- How To Be A Good DevOps Engineer?
- How to do git push, git pull, git add, git commit etc. with Bitbucket