#90DaysOfDevOps Challenge - Day 57 - Ansible Hands-on Project

#90DaysOfDevOps Challenge - Day 57 - Ansible Hands-on Project

Welcome to Day 57 of the #90DaysOfDevOps Challenge. Today, we will dive into an exciting hands-on project focused on practising Ansible installation, configuration, inventory file management, and ad-hoc commands. This project will provide you with valuable hands-on experience and help solidify your understanding of Ansible's core concepts and functionality.

Ansible Hands-on Project

Throughout this project, you will learn how to install Ansible on your control node, configure the inventory file to define your target hosts and execute ad-hoc commands to perform quick checks and tasks on the target hosts. You will also gain experience in writing and executing playbooks, which allow you to automate complex tasks and orchestrate workflows.

By working on this project, you will develop a solid understanding of Ansible's core concepts and functionality. You will become familiar with the process of setting up Ansible, managing inventory files, executing ad-hoc commands, and expanding your project by creating more advanced playbooks. This hands-on experience will boost your confidence and proficiency in using Ansible for automation and configuration management.

Now, let's dive into the step-by-step instructions to kickstart this hands-on project and start exploring the power of Ansible.

Task 1: Ansible Installation, Configuration, Inventory, and Ad-hoc Commands

To get started with the hands-on project, follow these step-by-step instructions:

  1. Install Ansible:

    • Open your terminal or command prompt.

    • Execute the following command to install Ansible:

        sudo apt update
        sudo apt install ansible
      

  1. Create an Ansible Project Directory:

    • Create a directory to serve as your Ansible project directory.

    • Change to the project directory using the following command:

        mkdir ansible-project
        cd ansible-project
      

  1. Configure the Inventory File:

    • Create a new file called inventory.ini using a text editor.

        sudo nano inventory.ini
      
    • Populate the file with the details of your target hosts, following the inventory file format:

        [servers]
        server1 ansible_host=<SERVER1_IP>
        server2 ansible_host=<SERVER2_IP>
        server3 ansible_host=<SERVER3_IP>
      

  1. Configure SSH Access:

    • Ensure that your control node can establish SSH connections to the target hosts.

    • Copy the public SSH key id_rsa.pub from the master node to the servers' authorized_keys files

  2. Practice Ad-hoc Commands:

    • Open your terminal or command prompt on the master node.

    • Execute ad-hoc commands to perform quick checks or tasks on the target hosts.

    • For example, to ping the target hosts, use the following command:

        ansible all -i inventory.ini -m ping
      

    • Execute shell commands on remote hosts. In this case, I will run the command id:

        ansible all -i inventory.ini -m shell -a "id"
      

    • Install packages using the package manager. In this case, I will install Docker on all servers.

        ansible all -i inventory.ini -b -m apt -a "name=docker.io state=present"
      

    • We can verify Docker is installed on Server1 by running the systemctl status docker command:

Congratulations on completing Day 57 of the #90DaysOfDevOps Challenge. By undertaking this hands-on project focused on Ansible installation, configuration, inventory file management, and ad-hoc commands, you have gained practical experience and a deeper understanding of Ansible's capabilities. Stay tuned for the next day, where we'll explore Ansible Playbooks.

Did you find this article valuable?

Support Esteban Moreno by becoming a sponsor. Any amount is appreciated!