How to automate any software installation and configuration using Ansible

How to Automate Any Software Installation and Configuration Using Ansible

Last Updated on February 5, 2024 by cscontents


In this article, we will discuss the steps involved in the automation of software installation and configuration using Ansible. This article is focused on Ansible, and how to achieve automated installation & configuration of software using Ansible. So, if you are interested in leveraging the power of Ansible to automate some of your manual tasks then this article will add some value to you.

A brief intro about Ansible, it is one of the most powerful automation tools 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.

Introduction to Ansible | High-Level Understanding of Ansible

If you want to learn Ansible basics then please check out the below course from KodeKloud which offers one of the best learning materials in the DevOps world.

Link of Training Course: Ansible for absolute beginners

Note: The above links are affiliate links, if you enroll in 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 tasks 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 –

  • Java
  • Web Server – JBoss EAP

We can easily automate the installation of these pieces of software using Ansible.

Speaking about the advantages of using Ansible for automation, once you develop the Ansible playbooks, you can reuse them which brings down your effort and saves time. For example, if you want to install Java & JBoss EAP on 10 machines then that automated solution would be very helpful.


To understand this tutorial, you need the below:

Prerequisite Knowledge

  • Hands-on knowledge on ansible – basic/intermediate level.
  • Knowledge of manual software installation – you need to know the steps to manually install the software that you want to automate using Ansible.

Prerequisite Setup

  • Two Linux machines – one machine will work as an ansible host (ansible controller) and another one will work as a target machine on which ansible will perform the task. For example, VM-1 will work as an ansible host and VM-2 will work as a target machine.

You can take a Windows machine also as a target machine, but for a Windows machine, you need to pass different parameters for the connection. You can refer below article to configure Windows machines as target machines.

How to connect with a Windows machine using Ansible

  • Ansible should be installed properly in one of the VMs (VM-1).
  • On the Linux target machine (VM-2) you need a non-root user with sudo privileges. In the case of Windows machines, one user is needed which has administrative privileges.
  • On the network level ansible host & target machine should be able to communicate. In the case of the Linux target machine port 22 should be open between them and in the case of the Windows target machine port 5985/5986 should be open between them.

Steps to Automate any Software Installation and Configuration

Below are steps that you can follow to automate any software installation and configuration using Ansible.

Step 1 – Gather the manual steps to install the software

Before we start automating any software installation the first step is we should have a 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 the case of Java installation on Linux below are the major tasks –

  • 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 an ansible module for each of the tasks. Ansible modules have been developed to perform a certain task. For almost all tasks 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 tasks.

Task Name

Ansible Module Name

Downloading the binaries get_url module
Unzipping downloaded zip files unarchive module
Updating /etc/profile file with JAVA_HOME lineinfile 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 files where we need to mention the tasks that you want Ansible to perform on the target machine. Once you are done with steps 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, and credentials of the target machine. You need to pass this inventory file while executing the playbook so that Ansible can use the information in the inventory file to connect with the target machine.

For example, ansible-playbook for automating Java installation can be found in the below article –

Automation of Java installation – using Ansible

Step 5 – Execute the playbook (YAML file)

If you are done with 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 playbook name.
  • inventory.txt – it is the inventory file where you need to put details about the target machine.

“-vv” is added for verbose output.

In 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 to the issue then you might get some help from Google, there is 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.

If you are in the 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 the installation is successful or not.


Thank You.

If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.