Showing posts with label Ansible. Show all posts
Showing posts with label Ansible. Show all posts

Tuesday, January 11, 2022

Ansible - Automation Essentials - Part 3 [ Parts of Ansible ]

How Ansible Works?

As already discussed, Ansible is a configuration management tool, based on push-based architecture to automate the configuration of your hosts to achieve the desired state.

Following are the components of Ansible architecture

  • Inventory - Defines the list of target hosts
  • Playbook (YAML file) - Defines a list of tasks
  • Module - A python code invoked from tasks and executed on hosts
  • Control Machine - Takes playbook and executes each task on a particular group of hosts

Playbook

A Playbook is a file that defines the desired state of your system.

It contains plays, which has a list of tasks to run in sequence against a list of hosts.

  • A play is a set of tasks, grouped together to achieve an objective
  • A task is an instruction you give to Ansible.
  • They are written in YAML format, a data serialization language, that we discussed in previous cards.

Inventory

So Ansible captured the desired state through Playbook, but how would ansible know which machines it should configure through Inventory?

The Inventory file in Ansible contains the list of all hosts (target systems/servers) that need to be configured. You can also group hosts under different names as shown:

[group A]

Host 1

[group B]

Host 2

Host N

More on Inventory

  • Default location of Inventory File: /etc/ansible/hosts
  • You can define an Inventory file statically (.ini file) or dynamically (.json file) to Ansible.

Modules Perform the Action

Modules are a piece of code that gets executed when you run a playbook. You use them to describe the state you want the host to be in.

Each task in play is made of modules and arguments.

Ansible - Automation Essentials - Part 2 [ Introduction to YAML Language ]

What is YAML?

YAML stands for Yet Another Markup Language. It is a data serialization language just like JSON.

Why YAML, when we already have JSON or XML?
  • YAML files are easy to read and write for humans, similar to English.

Foundation of YAML


  • YAML files should end as .yaml or .yml
  • Begins with --- and ends with
  • # defines comment

YAML is Case and Indentation Sensitive

  • Members of a list should be at the same indentation level starting with a dash(-) and space.
  • Each item in the list is a key: value pair (colon must be followed by a space), called a dictionary.
  • At each level, exactly two spaces are used for indentation. Using tabs is not recommended here.

Boolean Values

Variables can be defined in YAML files as shown:

stream: Java

allocated: true
allocated: yes

allocated: no

allocated: True

allocated: TRUE

allocated: false

Variables can be assigned boolean values in different ways as shown:

Data Structures

Complicated data structures are possible in YAML.

You can define lists having dictionariesdictionaries having lists or a mix of both.

In the following example,

  • name and job are dictionaries. Skill is a dictionary with a list.
  • David and Amy are listed as having dictionaries
# Employee records

- David:

name: David Moore

job: Developer

skills:

- python

- sql

- java

- Amy:

name: Amy Brown

job: Developer

skills:

- angular

- redux

- react

Ansible - Automation Essentials - Part 1 [ Introduction to Ansible in Ansible - Automation ]

What are You Going to Learn?

We hope you have gained a good understanding of what is Infrastructure as a code. In this course, you will learn about

  • Ansible and its benefits
  • Ansible in Infrastructure as Code (IaC)
  • YAML format
  • Few Ad_Hoc commands
  • Different parts of Ansible
  • Role of Modules in Ansible
  • How to write Playbooks
  • How to Control the flow of execution in Ansible
  • Few points about configuration file (ansible.cfg)
  • How to setup environment in local machine and online playground

By the end of this course, you will be in a position to write a few ad-hoc commands and a Playbook of your own.

What Is Infrastructure As Code?


IaC means writing code for infrastructure i.e. your systems and devices, which are used to run Softwares, are to be treated as software and defined using code(which can be done using a high level or descriptive language).

For example version control, testing, small deployments, use of design patterns, etc.

Configuration Management tools are used to accomplish IaC.

Why are You Here?


Infrastructure as Code can be achieved using Ansible, which is one of the popular Configuration Management tools. In this course, we will have you explore various capabilities of Ansible.

What is Configuration Management?


Configuration Management is a process of establishing, tracking and controlling the current design and build state of the system (software versions).

It also ensures that past records of system state are easily and accurately accessible which helps in project management, audit purposes, debugging etc.

Before Configuration Management

Consider you are planning for a New Year Special Sale on your e-commerce site. You need to

  • Scale up your servers
  • Then configure them(and all other old servers) for special new year sale
  • This whole process would take a lot of effort and time
  • What if new configurations did not work as expected? Then you will have to roll back to the previous stable version, which will add more work and subtract the profits and potential customers while in downtime.

Configuration Management Tools

You need some kind of Configuration Management tool that can automate these tasks:

  • Rollback to the stable version with zero downtime
  • Provide you with a constant computing environment throughout SDLC
  • Automatically scale up or down depending upon traffic

Some of the popular Configuration Management tools are Ansible, Puppet, Chef and Saltstack.

You will now learn more about Ansible in upcoming cards.

What is Ansible?


Ansible is open-source software, first released by Michael DeHaan in 2012 and owned by Red Hat.

It is used to automate

  • configuration management
  • application deployment
  • software provisioning and other IT needs

Benefits of Ansible

  • Simple: Very easy to install, set up and learn. Written in YAML file which is pretty much like reading English
  • Agentless: Do not need to install any agents on target nodes.
  • Powerful: It can model any complex IT workflow as it has 1100+ modules
  • Efficient: You can customize modules, using any programming language
  • Secure: Uses SSH for connection

Wondering about the YAML language?? Read on to discover 

Monday, January 10, 2022

Ansible - Automation Essentials - Part 0 [ Course Summary in Ansible - Automation ]


Here, we will introduce you to Ansible, how to set up and configure Ansible, execute Adhoc commands, configure roles, files, templates, etc. You will also play with Ansible Playbooks and modules.

Topics Covered

    • Ad-Hoc Commands
    • Modules - The Engine of Ansible
    • Set-Up Environment for Ansible
    • Playbook Explained
    • The Decision
    • Configuring Your Master
    • Write a PlayBook
    • Summary - Ansible
    • Ansible Final Assessment

      Please complete the entire course to get a good understanding and if you liked this then please like share and subscribe.