Ansible is a configuration management system written in the Python programming language. It is used to automate software configuration and deployment.It is an open source tool for managing software, configuration and deployment of applications across multiple hosts

    First, update the package index:
    sudo apt update

    Use the PPA repository for installation. Install software-properties-common, a package that makes it easy to manage independent software repositories.  
    sudo apt install software-properties-common  

    Then add the Ansible PPA repository using the following command:
    sudo apt-add-repository ppa:ansible/ansible

    Press the Enter key to join.  
    Once again, update the package base and install Ansible:  
    sudo apt update  
    sudo apt install ansible  

    After that, the Ansible software needed to administer your hosts will be installed on the server.

    Setting up access to hosts via SSH

    Use the following command to create an SSH key that will be used to connect to the hosts:
    ssh-keygen -t rsa -b 4096

    On the Ansible server, use the cat command to display the SSH public keys in the terminal:  
    cat ~/.ssh/  

    [email protected]:~# ssh-keygen -t rsa -b 4096
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa)
    Enter passphrase (empty for no passphrase)
    Enter same passphrase again
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/
    The key fingerprint is:
    SHA256:Zvr1I9IfDK3wCK9K5h5KtWBtC0R2ppUtgQOB/fikhNE [email protected]
    The key's randomart image is:
    +---[RSA 4096]----+
    |+=o.=+ |
    |ooE=o . |
    | oo+ . |
    |..o.o . |
    | .+++ . S . . |
    | ..=.o * + + |
    | . * . o.+ o |
    | . = . o ... o ... |
    | ..+.. .. oo. |
    [email protected]:~# cat ~/.ssh/
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQClTC6YhDZdHhiTj2UjDdOv5gpJufT0YKF6tnE1YwIFRrROBH8+hG7hyNlRtc7c5NGTp7fXXoVhnFRFe+thN/4ZDJ/1A44Pe91NldOBVovMlulk9RsRQqvLX8sZXLzY17i+2DINVF3aoOh6o3QEHrk3Axh+qz5DUYvJ70wM6GM40szUBf0wpA1GwoUaOmT4oZVDN6xRT05k++DGcik/EgwWy8hWK8hW8fmg5kXiWSvslLM8i/URaFFtTiFrna1NB75Rbl9brMLc3xMwUzqXRnohRBGbP/M7Js7HoaiS3yHqxIeo2JPVfdmxwpdCB2y14FTG0GU7gTeEOg6BUYNsSlU6IKv593RIGZ9hyPGnDiTZd3jgaOdOoYTKiHWj23zlrqqwSWbNQ== [email protected]

    Copy the generated key to each host to be served by Ansible:  
    ssh-copy-id [email protected]  

    For example: ssh-copy-id [email protected]

    Use a text editor to open the following configuration file:
    sudo nano /etc/ansible/hosts

    Using the following syntax, the [servers] group is defined with two different servers, each with its own indentifier: server1, server2. Be sure to replace the allocated IP addresses with the IP addresses of your Ansible hosts.  
    server1 ansible_host=your_server_ip_1  
    server2 ansible_host=your_server_ip_2  

    The servers:vars subgroup sets the ansible_python_interpreter host parameter, which will be valid for all hosts in the servers group. With this parameter value the remote server uses the Python 3 /usr/bin/python3 executable, not /usr/bin/python (Python 2.7)

    For example:
    server1 ansible_host=
    server2 ansible_host=


    Save your changes and close the file (CTRL + X, Y, Enter)  
    Important: The python language and the python-apt package must be installed on each host:  
    apt-get install python python-apt  

    Check connectivity

    By default Ansible connects to the remote host as root, if you use a different user you need to make additional settings. Create a directory in the configuration structure that contains the YAML files 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  

    Insert the following line with your user name instead of user_name:

    ansible_user: user_name

    Save your changes.  
    Note: individual hosts can be configured by creating aliases and naming files according to their alias in /etc/ansible/host_vars  
    To test the connection, run the ping command:  
    ansible -m ping all  

    server1 | SUCCESS => {
    { "changed": false,
    { "ping": "pong"
    server2 | SUCCESS => {
    { "changed": false,
    "ping": "pong"