Detailed understanding of concept of Playbooks in Ansible

Last updated on Nov 11 2021
Nitin Bajabalkar

Table of Contents

Detailed understanding of concept of Playbooks in Ansible

Ansible – Playbooks

In this blog, we will learn about Playbooks in Ansible.

Playbooks are the files where Ansible code is written. Playbooks are written in YAML format. YAML stands for Yet Another Markup Language. 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.

Playbook Structure

Each playbook is an aggregation of one or more plays in it. Playbooks are structured using Plays. There can be more than one play inside a playbook.

The function of a play is to map a set of instructions defined against a particular host.

YAML is a strict typed language; so, extra care needs to be taken while writing the YAML files. There are different YAML editors but we will prefer to use a simple editor like notepad++. Just open notepad++ and copy and paste the below yaml and change the language to YAML (Language → YAML).

A YAML starts with — (3 hyphens)

Create a Playbook

Let us start by writing a sample YAML file. We will walk through each section written in a yaml file.

---
name: install and configure DB
hosts: testServer
become: yes
vars:
oracle_db_port_value : 1521
tasks:
-name: Install the Oracle DB
yum: <code to install the DB>
-name: Ensure the installed service is enabled and running
service:
name: <your service name>

The above is a sample Playbook where we are trying to cover the basic syntax of a playbook. Save the above content in a file as test.yml. A YAML syntax needs to follow the correct indentation and one needs to be a little careful while writing the syntax.

The Different YAML Tags

Let us now go through the different YAML tags. The different tags are described below −

name

This tag specifies the name of the Ansible playbook. As in what this playbook will be doing. Any logical name can be given to the playbook.

hosts

This tag specifies the lists of hosts or host group against which we want to run the task. The hosts field/tag is mandatory. It tells Ansible on which hosts to run the listed tasks. The tasks can be run on the same machine or on a remote machine. One can run the tasks on multiple machines and hence hosts tag can have a group of hosts’ entry as well.

vars

Vars tag lets you define the variables which you can use in your playbook. Usage is similar to variables in any programming language.

tasks

All playbooks should contain tasks or a list of tasks to be executed. Tasks are a list of actions one needs to perform. A tasks field contains the name of the task. This works as the help text for the user. It is not mandatory but proves useful in debugging the playbook. Each task internally links to a piece of code called a module. A module that should be executed, and arguments that are required for the module you want to execute.

So, this brings us to the end of blog. This Tecklearn ‘Detailed understanding of concept of Playbooks in Ansible’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Ansible and build a career in DevOps domain, then check out our interactive, Configuration Management using Ansible Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

 

https://www.tecklearn.com/course/configuration-management-using-ansible/

Configuration Management using Ansible Training

About the Course

Tecklearn has specially designed this Configuration Management using Ansible Training Course to advance your skills for a successful career in this domain. The course will cover different components of Ansible and how they are used in software development operations.  You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Ansible.

Why Should you take Configuration Management using Ansible Training?

  • The average Ansible salary in USA is $136,500 per year or $70 per hour. Entry level positions start at $100,000 per year while most experienced workers make up to $187,500 per year.
  • Wells Fargo, Capital One, Apple, CISCO & many other MNC’s worldwide use Ansible across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Configuration Management using Ansible

  • What is Ansible?
  • Ansible vs Puppet
  • Ansible Architecture
  • Ansible Installation
  • Setting up Master Slave using Ansible
  • Configuring Ansible Roles
  • Write Playbooks
  • Applying configuration using Ansible
  • Hands on

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Detailed understanding of concept of Playbooks in Ansible"

Leave a Message

Your email address will not be published. Required fields are marked *