Quick Notes Series - Ansible
tutorialspoint

Quick Notes Series - Ansible

ANSIBLE QUICKSTART

Ansible is simple open source IT engine which automates application deployment, intra service orchestration, cloud provisioning and many other IT tools.Ansible is easy to deploy because it does not use any agents or custom security infrastructure, Ansible uses playbook to describe automation jobs, and playbook uses very simple language i.e. YAML

Ansible is a IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications — automate in a language that approaches plain English, using SSH, with no agents to install on remote systems

Ansible pushes small programs called as “Ansible Modules”. Ansible runs that modules on your nodes and removes them when finished. Ansible manages your inventory in simple text files, these are the hosts file. Ansible uses the hosts file where one can group the hosts and can control the actions on a specific group in the playbooks.

Configuration Management

Configuration management in terms of Ansible means that it maintains configuration of the product performance by keeping a record and updating detailed information which describes an enterprise’s hardware and software.

Such information typically includes the exact versions and updates that have been applied to installed software packages and the locations and network addresses of hardware devices

How Ansible Works?

Ansible works by connecting to your nodes and pushing out small programs, called "Ansible modules" to them. Ansible then executes these modules (over SSH by default), and removes them when finished. Your library of modules can reside on any machine, and there are no servers, daemons, or databases required.

The management node in the above picture is the controlling node (managing node) which controls the entire execution of the playbook. It’s the node from which you are running the installation. The inventory file provides the list of hosts where the Ansible modules needs to be run and the management node does a SSH connection and executes the small modules on the hosts machine and installs the product/software.

Interestingly Ansible removes the modules once those are installed so effectively it connects to host machine , executes the instructions and if it’s successfully installed removes the code which was copied on the host machine which was executed.

   Control machine − Machine from where we can manage other machines.

   Remote machine − Machines which are handled/controlled by control machine.

There can be multiple remote machines which are handled by one control machine. So, for managing remote machines we have to install Ansible on control machine.

Ansible - Playbooks

Playbooks are the files where Ansible code is written. Playbooks are written in YAML format.Playbooks are one of the core features of Ansible and tell Ansible what to execute. They are like a to-do list for Ansible that contains a list of tasks.

Playbooks contain the steps which the user wants to execute on a particular machine. Playbooks are run sequentially. Playbooks are the building blocks for all the use cases of Ansible.

Ansible - Roles

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules.

In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse. The breaking of playbook allows you to logically break the playbook into reusable components.

Each role is basically limited to a particular functionality or desired output, with all the necessary steps to provide that result either within that role itself or in other roles listed as dependencies.

Ansible - Variables

Variable in playbooks are very similar to using variables in any programming language. It helps you to use and assign a value to a variable and use that anywhere in the playbook. One can put conditions around the value of the variables and accordingly use them in the playbook.

Example

hosts : <your hosts>

vars:

tomcat_port : 8080

In the above example, we have defined a variable name tomcat_port and assigned the value 8080 to that variable and can use that in your playbook wherever needed.

Ansible - Facts

Before running any Tasks, Ansible will gather information about the system it's provisioning. These are called Facts, and include a wide array of system information such as the number of CPU cores, available ipv4 and ipv6 networks, mounted disks, Linux distribution and much more.

Facts are often useful in Tasks or Template configurations. For example Nginx is commonly set to use as many worker processors as there are CPU cores. Knowing this, you may choose to set your template of the nginx.conf.j2 file

Ansible - Templates

Template files can contain template variables, based on Python's Jinja2 template engine. Files in here should end in .j2, but can otherwise have any name. Similar to files, we won't find a main.yml file within the templates directory.

Ansible - Modules

Ansible uses "modules" to accomplish most of its Tasks. Modules can do things like install software, copy files, use templates and much more.

Modules are the way to use Ansible, as they can use available context ("Facts") in order to determine what actions, if any need to be done to accomplish a Task.

Anisble - Vault

We often need to store sensitive data in our Ansible templates, Files or Variable files; It unfortunately cannot always be avoided. Ansible has a solution for this called Ansible Vault. Vault allows you to encrypt any Yaml file, which typically boil down to our Variable files.

Vault will not encrypt Files and Templates.When creating an encrypted file, you'll be asked a password which you must use to edit the file later and when calling the Roles or Playbooks.

Ansible - Plugins

Plugins are pieces of code that augment Ansible’s core functionality. Ansible uses a plugin architecture to enable a rich, flexible and expandable feature set.

***Source - Doc Ansible and Tutorials Point

To view or add a comment, sign in

More articles by Anand Murthy

  • Docker Desktop for MacOS and its key features.

    I am using Docker engine since mid 2014 on my Linux and MacOS for building applications for testing, learning and also…

  • Quick Notes Series - SUSE Container Platform

    SUSE CaaS Platform Kubernetes, Ready for the Enterprise SUSE CaaS Platform is an enterprise class container management…

  • Quick Notes Series - Terraform

    Terraform Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform…

  • Quick Notes Series - Cloud Native

    Cloud Native Architecture Cloud native technologies empower organizations to build and run scalable applications in…

Insights from the community

Others also viewed

Explore topics