Devops - Ansible

Ansible is a tool for automating configuration of remote server instances. Meaning that a configuration can be written and ansible will ensure that the hosts targeted match that configuration. A key idea that is talked of as a selling point is that it is idempotent. This means that running the tool multiple times will not change the result. That is, if a server is already in the desired configuration ansible will not change anything that doesn’t match that configuration.

It only dependency is a working python installation on both the Control Node and the Managed Nodes.

It is another example of Infrastructure As Code. Most of the configuration files are specified in YAML but some are in a ini style syntax.

The inventory file, for example, is specified in this ini style and is used to specify any groups and hosts.

Glossary

Playbook

A collection of plays.

Play

A list of tasks and a list of hosts with which to act upon. May contains locally defined tasks or roles or both.

Task

A call to an Ansible module to perform an action of host such as running a shell command or performing a REST request.

Module

The units of code that Ansible executes.

Role

Is basically a repeatable group of configuration and tasks. Can be simplified to a list of tasks but is much more than that. Roles encapsulate all information needed to perform a particular configuration change.

The definition on the ansible docs website: Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure. After you group your content in roles, you can easily reuse them and share them with other users.

Collection

Collections are a distribution format for Ansible content that can include playbooks, roles, modules, and plugins. These can be installed through Ansible Galaxy and can be specified in requirements.yml

Group vars

Contains variables that apply to groups as specified in the inventory.

Host vars

Contains variables that apply to hosts as specified in the inventory.

Inventory

Optionally, this can be a folder or a file and contains hosts and also groups which those hosts may belong to.

Requirements.txt

Python dependencies if necessary to specify, could contain ansible version used.

Requirements.yml

Ansible dependencies if necessary. Contains collections or roles that plays in a project might be dependant on.

Folder Structure

An example folder structure for a project is shown below: