Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to automate any software installation and configuration using Ansible

In this article, we will discuss 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 want to leverage 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

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 -

1. Java
2. 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.

Prerequisite

To understand this tutorial, you need the below:

Prerequisite Knowledge

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

Prerequisite Setup

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 the Windows machine as the target machine.

How to connect with Windows machine using Ansible

  • Ansible should be installed properly in one of the VMs (e.g. VM-1).
  • On the target Linux machine (VM-2) you need a non-root user with sudo privileges. In the case of a Windows machine, 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 a 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.

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 the 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 an 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 certain tasks. For almost all tasks ansible has a module, which is a great thing.

In step 2, we discussed the major task for Java installation. Below are the ansible modules which can be used for each of the tasks.

Again repeating, here for example purposes 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 which 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. And 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 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

Here,

  • 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 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 take 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.

When 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 take 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

Originally published at https://cscontents.com on December 16, 2022.

👋 If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Join FAUN Developer Community & Get Similar Stories in your Inbox Each Week


How to automate any software installation and configuration using Ansible was originally published in FAUN — Developer Community 🐾 on Medium, where people are continuing the conversation by highlighting and responding to this story.

Share the post

How to automate any software installation and configuration using Ansible

×

Subscribe to Top Digital Transformation Strategies For Business Development: How To Effectively Grow Your Business In The Digital Age

Get updates delivered right to your inbox!

Thank you for your subscription

×