Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Automation»How To Install and Configure Ansible on Debian 10

    How To Install and Configure Ansible on Debian 10

    By RahulOctober 3, 20204 Mins Read

    Ansible is a free and easy to use automation tool for managing multiple remote hosts from the single machine. It provides you with an easy to configure for a large number of remote hosts. For example, you are performing the same tasks over multiple machines, Ansible provides you the option to automate these tasks.

    Advertisement

    Ansible is a better alternatives of the other popular infrastructure automation tools available like Chef and Puppet. You don’t need to install any client software on nodes to manage through Ansible server. It uses SSH connection to execute tasks on hosts.

    This tutorial will help you to install and configure Ansible on Debian 10 Linux systems.

    Prerequisites

    For this tutorial, I have the following hosts:

    • One Control Node – To build your infra with Ansible, you need a control node where Ansible server will run. This is known as Ansible control node.
    • One or more Hosts – We have three hosts running with different-2 operating systems.
      • Two hosts with Ubuntu 20.04 LTS
      • One host with CentOS 8

    Step 1 – Configure SSH Keys

    Ansible control node uses ssh connection to connect hosts. You can configure Ansible to connect hosts using the password or key-based ssh access. In this tutorial, we will use both (password and key based ssh) types to connect hosts from control node.

    Login to Ansible control node and generate ssh key pair (if not generated):

    ssh-keygen -t rsa 
    

    Just press “Enter” to all the input asked by the command.

    Then copy the public key to the remote hosts, you need to connect via key-based:

    ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] 
    ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] 
    

    Step 2 – Installing Ansible on Debian

    The Ansible debian packages are available under the official Apt repository. You just need to add the PPA to your system. Use the following command to add Ansible debian repository to your system:

    sudo apt-add-repository ppa:ansible/ansible 
    

    Software Updater utility will update the packages cache on your system. So you have to run the following command to install or update Ansible on your Debian system

    sudo apt update 
    sudo apt install ansible 
    

    Press ‘Y’ for all the installation confirmation to complete install process. Next, you need to configure Ansible server

    Step 3 – Create Inventory File

    You have installed Ansible server on your control node.

    Now, you need to add the hosts to the Ansible server. Ansible allows to manage hosts in the form on hosts and groups. The Groups are used for performing one task on all remote hosts defined under it.

    A single host can be added to multiple groups. Edit Ansible hosts configuration file. For example:

    sudo nano /etc/ansible/hosts 
    

    Add your hosts and organize them with groups:

    [webservers]
    web-host1
    web-host2
    
    [dbservers]
    db-host1
    
    [ubuntu]
    web-host1
    db-host1
    
    [centos]
    web-host2
    

    The below image will help you to understand group and hosts under a group.

    Per Host Configuration

    You can create configuration files for individual hosts. All the hosts configuration file resides under /etc/ansible/host_vars directory with the same as hostname.

    sudo mkdir /etc/ansible/host_vars/ 
    sudo vi /etc/ansible/host_vars/web-host1 
    
    • 1’st Host – /etc/ansible/host_vars/web-host1
      ansible_ssh_host: 10.0.1.101
      ansible_ssh_port: 22
      ansible_ssh_user: root
      
    • 2’nd Host – /etc/ansible/host_vars/web-host2
      ansible_ssh_host: 10.0.1.102
      ansible_ssh_port: 22
      ansible_ssh_user: root
      
    • 3’rd Host – /etc/ansible/host_vars/db-host1
      ansible_ssh_host: 10.0.1.103
      ansible_ssh_port: 22
      ansible_ssh_user: root
      
    • In case you don’t have used Step 1 for the ssh connection for this host. You can also add one of the below methods to web-hosts1 configuration file for the authentication.

      ansible_ssh_pass: secret_password
      ansible_ssh_private_key_file: /home/rahul/.ssh/aws.pem
      

      Group Vars Configuration

      You can configure common variable settings of a Group under group configurations. The group file name must be same as the group name (eg: webservers) under group_vars directory.

      sudo mkdir /etc/ansible/group_vars 
      sudo vi /etc/ansible/group_vars/webservers 
      

      Add the common variables to this file used by all the hosts added under this group.

      ansible_ssh_port: 22
      ansible_ssh_user: root
      

      Step 4 – Testing Ansible Connection

      Your Ansible is ready to use. To test all nodes connectivity use ping module. Login to your Ansible server and execute following command:

      ansible -m ping all 
      

      You can also test connectivity for the specific host or groups.

      ansible -m ping web-host1         ## Specific host 
      ansible -m ping webservers        ## Specific group 
      

      You can also run any Linux command using the Ansible shell module. For example, execute the below command to test the free memory on web-host1.

      ansible -m shell -a 'free -m' web-host1 
      

      Install Ansible on Debian

      You can also perform the same task for a group. Just use group name instead of hostname.

      Conclusion

      In this tutorial, you have learned to install and configure Ansible on Debian 10 Linux system.

    Ansible Automation Automation Tool Debian 10
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Setup Selenium with Python and Chrome on Ubuntu & Debian

    Setup Selenium with Python and Chrome Driver on Ubuntu & Debian

    How to Setup Selenium with Python and Chrome on Fedora

    Setup Selenium with Python and Chrome on Fedora

    How to Install Tomcat 10 on Debian 10

    How to Install Tomcat 10 on Debian 11/10

    View 2 Comments

    2 Comments

    1. waheed on July 14, 2021 7:46 am

      Hi,
      Mr.Rahul
      Thanks a lot for such a nice tech info website , i would like to learn how to install |Ansible dashboard on Debian 10.
      i will be Thank full for your great help.

      Regards,
      waheed

      Reply
    2. Milos on October 30, 2020 11:38 am

      Hi Rahul, is the any way to show installation of Ansible Tower and example how it works like you did in this blog?

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.