Ansible - Introduction with essential playbook features

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 
(It’s a human-readable data serialization language & is commonly used for configuration files, but could be used in many applications where data is being stored)
which is very easy for humans to understand, read and write. 
Hence the advantage is that even the IT infrastructure support guys can read and understand the playbook and debug if needed (YAML – It is in human readable form).
Ansible is designed for multi-tier deployment. Ansible does not manage one system at time, it models IT infrastructure by describing all of your systems are interrelated. 

Ansible is completely agentless which means Ansible works by connecting your nodes through ssh(by default). But if you want other method for connection like Kerberos, Ansible gives that option to you.
After connecting to your nodes, 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.

For Ansible, nearly every YAML file starts with a list. Each item in the list is a list of key/value pairs, commonly called a “hash” or a “dictionary”. So, we need to know how to write lists and dictionaries in YAML.
All members of a list are lines beginning at the same indentation level starting with a “- ” (dash and space). More complicated data structures are possible, such as lists of dictionaries or mixed dictionaries whose values are lists or a mix of both.

Essential Playbook Features:


Variables:

Define variables in multiple ways:

# 1. In-playbook

vars:

app_user: "deployer"


# 2. External vars file (vars.yml)

app_port: 8080


# 3. Command-line override

ansible-playbook playbook.yml --extra-vars "app_user=admin"


Conditionals:

- name: Install EPEL on CentOS
  yum:
    name: epel-release
    state: present
  when: ansible_facts['os_family'] == "RedHat"

 

Loops:

- name: Install multiple packages
  apt:
    name: "{{ item }}"
    state: present
  loop:
    - git
    - curl
    - htop


Comments

Popular posts from this blog

Interview question for File and FTP Adapter

What is boot.properties file and how to create

SSL Exceptions in Admin Server and Node Manager.