Automating infrastructure with Ansible

The objective of this lab is to;
  • Install ansible in a Linux Server
  • Setup ansible hosts (inventory)
  • Ping hosts from the control node
Introduction

In today’s fast-paced Devops environment, automation is key. Ansible, a powerful IT automation tool, makes it easier to manage infrastructure as code whether you are provisioning servers, installing applications or configuring network devices, Ansible allows you to streamline these tasks with simple YAML-based playbooks.

Why Ansible?
    • Agentless: Ansible uses SSH to connect to nodes, eliminating the need for agents.

    • Simple syntax: Playbooks are written in YAML, which is easy to read and write.

    • Idempotent: Running the same playbook multiple times leads to the same system state.                                                                                                            

1. Installation of ansible

 To achieve the task of system configuration, we will have a central or control node where all tasks will be performed and push to the remote server. 3 VM were provisioned in Vmware Esxi with terraform.

Control node Requirement for your control node (the machine that runs Ansible), you can use nearly any UNIX-like machine with Python installed. This includes Red Hat, Debian, Ubuntu, macOS, BSDs, and Windows under a Windows Subsystem for Linux (WSL) distribution. Windows without WSL is not natively supported as a control node.                                 

    •  
    Project infrastructure
    sudo apt update
    sudo apt install software-properties-common -y
    sudo add-apt-repository --yes --update ppa:ansible/ansible
    sudo apt install ansible -y. This command will install ansible
    ansible --version. This command will verify if ansible is installed.
    2- Creation of ansible directories

    After successfully installing ansible in the control node, next will be to create a directory of the project.

    I will a create a project directory called Infrastructure-automation (infra-auto). Run the command “mkdir infra-auto” to create infra-auto directory.

    Run the command “cd infra-auto” and create another directory call ansible by running the command “mkdir ansible”.

     Change directory “cd ansible” and create two more directories by running the command “mkdir inventory” and “mkdir playbooks”

    next, cd into inventory and create file with ini extension name hosts.ini by running the command “nano hosts.ini” the file will contain all the hosts to be manage in the infrastructure.

    Add the following in the hosts.ini file
    3- Ping hosts from the control nodeRun the command "ansible -i inventory/hosts.ini devops -m ping" this command will ping the hosts in hosts.ini file

    From the above, we were able to install ansible in the control node, setup the hosts sever and successfully ping the hosts server from the control node. In the upcoming labs, we will create ansible playbooks for system automation like patches, backup, installing applications and much more.

    If this was helpful, lets connect in the comment section

     

    Leave a Reply

    Your email address will not be published. Required fields are marked *