What Is Ansible?
Ansible is an open source IT Configuration Management, Deployment & Orchestration tool. It aims to provide large productivity gains to a wide variety of automation challenges. This tool is very simple to use yet powerful enough to automate complex multi-tier IT application environments.
Why Do We Need Ansible?
Let us take a little flashback to the beginning of networked computing when deploying and managing servers reliably and efficiently has been a challenge. Previously, system administrators managed servers by hand, installing software, changing configurations, and administering services on individual servers.
As data centers grew, and hosted applications became more complex, administrators realized they couldn’t scale their manual systems management as fast as the applications they were enabling. It also hampered the velocity of the work of the developers since the development team was agile and releasing software frequently, but IT operations were spending more time configuring the systems. That’s why server provisioning and configuration management tools came to flourish.
Consider the tedious routine of administering a server fleet. We always need to keep updating, pushing changes, copying files on them etc. These tasks make things very complicated and time consuming.
But let me tell you that there is a solution to the above stated problem. The solution is — Ansible.
- Controller Machine: The machine where Ansible is installed, responsible for running the provisioning on the servers you are managing.
- Inventory: An initialization file that contains information about the servers you are managing.
- Playbook: The entry point for Ansible provisioning, where the automation is defined through tasks using YAML format.
- Task: A block that defines a single procedure to be executed, e.g. Install a package.
- Module: A module typically abstracts a system task, like dealing with packages or creating and changing files. Ansible has a multitude of built-in modules, but you can also create custom ones.
- Role: A pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of a provisioning.
- Play: A provisioning executed from start to finish is called a play. In simple words, execution of a playbook is called a play.
- Facts: Global variables containing information about the system, like network interfaces or operating system.
- Handlers: Used to trigger service status changes, like restarting or stopping a service
Restarting HTTPD Service is not idempotence in nature and also consume more resources.. Suggest a way to rectify this challenge in Ansible Playbook.
👉The following Ansible Playbook accomplishes the following tasks:
- Mounts CDROM on a directory in the Target Node
- Updates YUM repo list
- Installs HTTPD server
- Configures the service (including the changing of default Document Root)
- Copies webpage from Controller Node to the Target Node
- Exposes the port on which HTTPD server is running
- Starts the service
So Let’s write a playbook now for doing all this jobs
- hosts: all
- name: “Creating CDROM’s mount point.”
- name: “Mounting CDROM”
- name: “Creating yum repo 1”
description: “CDROM Repo 1”
- name: “Creating yum repo 2”
description: “CDROM Repo 2”
- name: “Installing HTTPD Server”
- name: “Creating new directory for root to configure HTTPD”
- name: “Copying new conf file for HTTPD”
- name: “Copying content to Document root”
content: “This is my webpage”
- name: “Exposing the port”
- name: “Restarting HTTPD Service”
changed_when: “‘already running’ not in startoutput.stdout”
📌Let’s now run the playbook
So we can see the HTTPD service is restarting
Congrats. The work is done
If you find it interesting please upvote it.