Introduction to Ansible

In this blog Introduction to Ansible you will learn about the main components on Ansible.

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. Simple, powerful, and agentless IT automation that anyone can use. It uses SSH to connect to servers and run the configured Tasks. Ansible lets you control and configure nodes from a single machine. The project was found in 2013 and bought by Red Hat in 2015.

Why Ansible?

No Agent- As long as the box can be ssh’d into and it has python, it can be configured with Ansible. Idempotent- Ansible’s whole architecture is structured around the concept of idempotency. The core idea here is that you only do things if they are needed and that things are repeatable without side effects. Declarative Not Procedural- Other configuration tools tend to be procedural do this and then do that and so on. Ansible works by you writing a description of the state of the machine that you want and then it takes steps to fulfill that description.

Tiny Learning Curve- Ansible is quite easy to learn. It doesn’t require any extra knowledge.

Ansible Use Cases:

  1. Provisioning
  2. Configuration Management
  3. App Deployment
  4. Continuous Delivery
  5. Security & Compliance
  6. Orchestration

Architecture of Ansible:

Image for post
Image for post

Playbooks in Ansible?

  1. Plain-text YAML files that describe the desired state of something
  2. Human and Machine-readable
  3. Can be used to build the entire application environment
Image for post

Inventories in Ansible?

  1. Static lines of servers
  2. Dynamic list of servers: AWS, Azure, GCP, etc.
  3. Ranges
  4. Other custom things
Image for post
Image for post

Modules in Ansible?

  1. Over 1000 modules provided by Ansible to automate
  2. Modules are like plugins that do the actual work in Ansible, they are what gets executed in each playbook task.
  3. Each module is mostly standalone and can be written in a standard scripting language (such as Python, Perl, Ruby, Bash, etc.)
Image for post

What are roles in Ansible?

  1. Roles are a way to group tasks together into one container. We could have a role for setting up MySQL, another one for configuring ip tables.
  2. Roles make it easy to configure hosts. Any role can be performed on any host or group of hosts such as:

– hosts: all
– roles:
– role_1
– role_2

Variables in Ansible?

There are many different ways to source variables:

  1. Playbooks
  2. Files
  3. Inventories (group vars, host vars)
  4. Command-line Discovered Variables
  5. Ansible Tower

How to Run the Ansible Commands?

Ad-Hoc: Ansible <inventory> -m

Playbooks: Ansible-playbook

Image for post
Image for post

AD-HOC Commands Examples:

Transferring file to many servers/machines

$ Ansible abc -m copy -a “src = /etc/yum.conf dest = /tmp/yum.conf“

Creating new directory

$ Ansible abc -m file -a “dest = /path/user1/new mode = 777 owner = user1 group = user1 state = directory“

Deleting whole directory and files

$ Ansible abc -m file -a “dest = /path/user1/new state = absent”

Ansible Tower

Ansible Tower is a GUI and REST interface for Ansible that supercharges it by adding RBAC, centralized logging, auto-scaling/provisioning call-backs, graphical inventory editing, and more.

Capabilities ::

This command line tool sends commands to the Tower API. It is capable of retrieving, creating, modifying, and deleting most resources within Tower.

A few potential uses include:

  1. Launching playbook runs (for instance, from Jenkins, TeamCity, Bamboo, etc.)
  2. Checking on job statuses
  3. Rapidly creating objects like organizations, users, teams, and more.
Image for post

For any query related to Ansible comment below or contact us

Recommended Courses

VILT & Self-Paced

AZ-204 Developing Solutions for Microsoft Azure

This self-paced course will help you prepare for the Azure Developer certification exam AZ-204: Developing Solutions for Microsoft Azure.


AZ-900: Microsoft Azure Fundamentals Tutorial

AZ-900: Microsoft Azure Fundamentals Tutorial provides foundational level knowledge on cloud concepts; core Azure services; security, privacy, compliance, and trust; and Azure pricing and support.


AZ-400 Designing and Implementing Microsoft DevOps Solutions

This self-paced course will help you prepare for the Azure DevOps certification exam AZ-400: Designing and Implementing Microsoft DevOps Solutions.