Ansible: Basic Installation And Set-Up
In a slew of IT automation engines that have emerged in recent years, Ansible is one of the latest additions to the market. It is a great tool to execute mass changes across multiple systems. It is popular in both home-lab environments as well as corporate set-ups. Using Ansible removes the drudgery from your daily work by automating monotonous system administration tasks and improving the scalability, consistency, and reliability of your IT setup.
In this article, we discuss the steps of Getting started with Ansible.
What is Ansible?
It is an open-source software, application deployment tool and configuration management written by Michael DeHaan. Ansible enables infrastructure as a code and runs on several Unix-like operating systems like Windows, macOS, and Linux.
Why Ansible, you might ask. The answer simply lies in understanding exactly how Ansible helps make your life easier.
- Provisioning: Ansible helps you set up the various servers needed for your IT infrastructure
- Configuration management: Ansible helps you automate changes in the configuration of an application, OS or any device. It helps in service automation, installation of updates and implementation of security policies.
- Application deployment: Ansibles helps automate the deployment of internally developed applications, thus making DevOps easier.
Ansible automates IT environments hosted on both traditional metal servers or in the cloud. It also automates the configuration of a range of devices like storage devices and systems like databases, networks, firewalls, and the like.
An advantage of using Ansible is that you do not need to keep track of each and every command used to accomplish a particular task. All you need to do is specify the state you want your system to be in and Ansible takes care of the rest.
Ansible Installation Steps And How To Set Up
Ansible is an agentless tool that is installed on a control node. Ansible manages your systems remotely (by default, over the SSH protocol) from that single control node.
The first step is to simply install the Ansible package on any one of your machines like a laptop. No database is needed to be installed. You don’t also need to run any daemons. Ansible manages your entire remote system from one control node.
Before you install Ansible, you need to review the requirements of a control node.
For your control node, any machine with Python 2 installed on it can be used.
When choosing a control node, it is always advisable to remember that the management system performs better if it is near the machines that it manages. For example, if you are using Ansible to manage machines on the cloud, then it is wise to choose your control node from inside that cloud.
Selecting an Ansible version to install
As of version 2.10, there are two artifacts of Ansible that you can use. A community package called Ansible and runtime and minimalist language called Ansible-base. You need to review your particular needs and choose the one that fits them the best.
Installing Ansible Community Package
This package has the runtime and Ansible language plus a variety of community curated collections. The steps to install this are:
- Your OS package manager should be updated with the latest version
- Install with pip (the Python package manager)
Ansible-base includes the Ansible language, runtime, and a shortlist of core modules and also other plugins. The steps to install this are:
- Install ansible-base with pip
- Install ansible-base from the source/ansible GitHub repository to get access to the development version to work with the latest features.
Installing Ansible with pip
If pip is not present, you can run this command to install it:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py –user
You might need to go through a few additional configurations before you can install and run Ansible.
Once you have installed pip, you can install Ansible using the following command:
$ python -m pip install –user ansible
Installing Ansible on specific operating systems
To configure the PPA on Ubuntu and then install Ansible in your system, run these commands:
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository –yes –update ppa:ansible/ansible
$ sudo apt install ansible
Using pip is the most convenient way to install Ansible on a Mac.
If you have macOS version 10.12 or older, then you need to upgrade to the latest pip to connect to the Python Package Index securely. The pip must be run as a module on macOS, and the linked pip instructions will show you how to do the rest.
If you are installing on macOS Mavericks (10.9), you may encounter some issues. An easy solution is to run the following command:
$ CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install –user ansible
Confirming your installation
Whatever method you install Ansible with, you can test your installation with a ping command:
$ ansible all -m ping –ask-pass
You can also use “sudo make install”.
Ansible Inventory and Playbooks
The two main features of Ansible that are used are:
- Inventories, which is a store of all of your hosts
- Playbooks, which contain the “instructions” to execute on the hosts.
For Ansible to read and execute your playbook, it has to know where the hosts are. That is basically what the inventory file is.
Ansible is a powerful and versatile tool that can be used to perform a variety of functions. Once you have installed it and gone through the basic setup steps, you can experiment with it to discover more advanced functionalities.
If you are an aspiring DevOps professional or you just want to make your life easier by automating your administration tasks, Ansible is a good place to begin your automation journey.