How to install and configure Ansible on Ubuntu 18.04

Instructions for installing Ansible on a virtual server running .

What is Ansible?

Ansible is one of the main trends in the automation of technological processes and production using tools. It is an open-source tool for software management, configuration and deployment of applications across multiple hosts. Ansible is fairly easy to use, yet powerful enough to automate complex, layered IT application environments.

Installing and configuring Ansible on Ubuntu

Installation

Update your local package :

sudo apt update

First, install the software-properties-common package, which allows you to easily manage distributions and third-party software sources:

sudo apt install software-properties-common

With this tool, you can manage personal package archives (PPAs), which allow you to distribute your own packages and utilities without too much complexity.

Then add the Ansible PPA repository with the following command:

sudo apt-add-repository ppa:ansible/ansible

During the connection process, you will need to press the Enter key.

Update the package database again and install Ansible:

sudo apt updatesudo apt install ansible

The virtual server now has the Ansible software required to administer your hosts.

Configuring to hosts via

Ansible primarily communicates with client computers via SSH.

Our instructions cover the use of SSH keys, because. this method helps simplify the connection process and is more secure than using passwords.

You can read more about what SSH keys are and how to work with them in our guide.

Use the following command to create an SSH key that will be used to connect to hosts:

ssh-keygen -t rsa -b 4096

Copy the generated key to each host that will be served by Ansible:

ssh-copy-id user_name@ip-address

: ssh-copy-id root@123.122.123.122

Using a text editor, open the following configuration file:

vi /etc/ansible/hosts

Using the following syntax, where group_name is a convenient name for a group of and your_server_ip_1 and your_server_ip_2 are the IP addresses of the servers you serve, add lines to the open hosts file:

[group_name]
your_server_ip_1
your_server_ip_2

For example:

[servers_ubuntu]
123.122.123.122
46.122.123.20

Save changes and close the file.

Important: Each host must have the python language and the python-apt package installed:

apt-get install python python-apt

Connectivity Check

By default, Ansible connects to the host as the root user, if you are using a different user, then you need to make additional settings. Create a directory in the configuration structure that will contain the YAML for each group:

sudo mkdir /etc/ansible/group_vars

Create a subdirectory with the name of your group:

sudo nano /etc/ansible/group_vars/group_name

For example:

sudo nano /etc/ansible/group_vars/servers_ubuntu

Insert the following line, replacing user_name with your username:

---
ansible_user: user_name

Save your changes.

Note: Individual hosts can be configured by creating aliases and files named according to their alias in the /etc/ansible/host_vars directory

To check the connection, run the ping command:

ansible - ping all

Expected Result:

123.122.123.122 | SUCCESS => {
    "changed": false
    "ping": "pong"
}

46.122.123.20 | SUCCESS => {
    "changed": false
    "ping": "pong"
}

 

Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of us as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and web hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!