How to setup Ansible on Ubuntu

Install Ansible on Ubuntu

How to setup Ansible on Ubuntu

What is Ansible?

Ansible is the #1 configuration management tool. It can also be used for infrastructure provisioning as well. or You can use Ansible in a combination with Terraform which can take care of infra automation and Ansible can do configuration management.

Ansible Architecture

Basic components of an Ansible environment include a control node, an inventory of managed nodes, and a module copied to each managed node.

Ansible concepts

  • Control-Node:

    The machine from which you run the Ansible CLI tools (ansible-playbook , ansible, ansible-vault and others). You can use any computer that meets the software requirements as a control node - laptops, shared desktops, and servers can all run Ansible. Multiple control nodes are possible, but Ansible itself does not coordinate across them, see AAP(Ansible Automation Platform)for such features.

  • Managed Node:

    Also referred to as ‘hosts’, these are the target devices (servers, network appliances or any computer) you aim to manage with Ansible. Ansible is not normally installed on managed nodes unless you are using ansible-pull, but this is rare and not the recommended setup.

  • Inventory:

    A list of managed nodes provided by one or more ‘inventory sources’. Your inventory can specify information specific to each node, like IP address. It is also used for assigning groups, which both allow for node selection in the Play and bulk variable assignment. Sometimes an inventory source file is also referred to as a ‘hostfile’.

  • Playbooks:

    They contain Plays (which are the basic unit of Ansible execution). This is both an ‘execution concept’ and how we describe the files on which ansible-playbook operates. Playbooks are written in YAML and are easy to read, write, share and understand.

  • Modules:

    The code or binaries that Ansible copies to and executes on each managed node (when needed) to accomplish the action defined in each Task. Each module has a particular use, from administering users on a specific type of database to managing VLAN interfaces on a specific type of network device. You can invoke a single module with a task, or invoke several different modules in a playbook. Ansible modules are grouped in collections.

The best way to install Ansible for Ubuntu is to add the project's PPA (personal package archive) to your system. You also would need the Boto framework for provisioning resources in the AWS cloud.

Pre-requisites:

Create a new Ubuntu EC2 instance for installing Ansible, just open port 22.

Update the Repository by including the official project’s PPA(personal package archive):

sudo apt update -y

sudo apt-add-repository -y ppa:ansible/ansible

Then you need to refresh the package by executing the below command:

sudo apt update -y


Now let's install Ansible:

Now install ansible by executing the below command:

sudo apt install ansible -y

Then install Package manager for python:

sudo apt install python-pip -y

Install Boto Framework - AWS SDK

sudo pip install boto boto3

Ansible will access AWS resources using boto SDK.

sudo apt install python-boto -y

pip list boto | grep boto

Ignore the warning in Red color.

Now check the version of the ansible by executing the below command:

ansible --version


Conclusion:

As a last thought, I conclude that Ansible exists to offer a straightforward and effective package for configuration management and automation. Being new to the software application market, Ansible faces tough competition from renowned sources.

In this article, I have tried my best to cover as maximum as possible important aspects of Ansible to make you aware of this technology in the best possible way.

Did you find this article valuable?

Support Biswajit Mohapatra by becoming a sponsor. Any amount is appreciated!