Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Ansible Tutorial: Anatomy of Ansible playbook defined!

  • A Play performs one or more Tasks against one or more Managed Nodes.
  • Each playbook is composed of one or more ‘plays’ in a list.
  • A play map a group of hosts to some well defined roles, represented by tasks.
  • Plays run in the order specified: top to bottom.

Example

---
- name: Start the Play          # describes WHAT we are doing
- hosts: all # one or more group or host patterns
  order: sorted # Host order: value can be 'inventory' ie as is in the inventory file, reverse_inventory, sorted (alpha), reverse_sorted, shuffle (random)
  remote_user: yourname # or root This property was called user before Ansible 1.4
  become: yes # optional
  become_user: postgres # optional
  gather_facts: False
  order: inventory # Default
  connection: local or network_cli
  serial: 1 OR 30%
  max_fail_percentage
  strategy: free
  any_errors_fatal: True

where:

--- separates playCode language: PHP (php)

host defines the target machines: one or more groups or host patterns, separated by colons that should match hosts in the inventory. all is a group that means all hosts in the inventory file.

remote_user, become and become_user are connection variable
remote_user defines the default logging remote user (The remote user can also be defined for a task)

gather_facts defines if fact must be gathered

become and become_user defines user escalation mechanism

gather_facts defines if fact must be gatheredgather_facts defines if fact must be gathered

order – Control the order in which hosts are run. The default is to follow the order supplied by the inventory. Possible values for order are:

inventory: The default. The order is โ€˜as providedโ€™ by the inventory

reverse_inventory: As the name implies, this reverses the order โ€˜as providedโ€™ by the inventory
sorted: Hosts are alphabetically sorted by name
reverse_sorted: Hosts are sorted by name in reverse alphabetical order
shuffle: Hosts are randomly ordered each run.

max_fail_percentage – max_fail_percentage can be used to abort the run after a given percentage of hosts has failed.

strategy – A strategy ships with Ansible – free – which allows each host to run until the end of the play as fast as it can.

serial – You can define how many hosts Ansible should manage at a single time by using the serial keyword. The serial directive can โ€˜batchโ€™ this behaviour to a subset of the hosts, which then run to completion of the play before the next โ€˜batchโ€™ starts. The serial keyword can also be specified as a percentage, which will be applied to the total number of hosts in a play, in order to determine the number of hosts per pass:

any_errors_fatal – With the โ€˜โ€™any_errors_fatalโ€™โ€™ option, any failure on any host in a multi-host play will be treated as fatal and Ansible will exit immediately without waiting for the other hosts.

Lets understand each piece, letโ€™s look at the overall construction of a Play.

---
- name: Start the Play          # describes WHAT we are doing
  hosts: application            # describes WHERE we are doing it (e.g. against all application hosts)
  become: false                 # describes HOW we are doing it (with priviledge escalation, by gather facts, serial batches, etc)
  gather_facts: true
  serial: 10

  vars:
    app_path: /opt/app

  environment:
    PATH: /my/folder:

  pre_tasks:

  roles:

  tasks:

  post_tasks:

Code language: PHP (php)

Playbook – A Playbook is a file containing one or more Plays.

--
- name: Start the first Play    # describes WHAT we are doing
  hosts: application            # describes WHERE we are doing it; what target hosts
  become: false                 # describes HOW we are doing it (with priviledge escalation, by gather facts, serial batches, etc)
  gather_facts: true
  serial: 10

  # vars, environment, pre_tasks, roles, tasks, post_tasks, etc.

- name: Start the second Play
  hosts: webservers
  become: true
  gather_facts: false
  serial: 5

  # vars, environment, pre_tasks, roles, tasks, post_tasks, etc.Code language: PHP (php)

Role

role-foobar/
โ”œโ”€โ”€ defaults
โ”‚   โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ vars
โ”‚   โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ files
|   โ””โ”€โ”€ foobar.txt
โ”œโ”€โ”€ handlers
โ”‚   โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ meta
โ”‚   โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ tasks
โ”‚   โ””โ”€โ”€ main.yml
โ””โ”€โ”€ templates
    โ””โ”€โ”€ foobar.conf.j2

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Ansible Tower Install and Setup Quick Guide

To installย Red Hat Ansible Tower 3.8.6ย (usingย ansible-tower-setup-3.8.6-2.tar.gz), your environment must meet a set of hardware, software, and system prerequisites. Below are the summarized requirements specific to this Tower…

Read More

Ansible: How to use template in Ansible using Jinja2?

Hereโ€™s a comprehensive tutorial on Ansible Templates and Jinja2, suitable for engineers or anyone preparing for an advanced Ansible role. 1. What are Ansible Templates? Ansible templates…

Read More

What is Ansible and use cases of Ansible?

What is Ansible? Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It simplifies complex IT tasks by automating them using…

Read More

Ansible Tutorials: Calling one Play & Tasks from another play in Playbook

import_tasks module The Ansible import_tasks module is used to import a list of tasks from a file into the current playbook for subsequent execution. The name of…

Read More

Complete Ansible Certification Guide & tutorials

What is Ansible? Ansible is an open-source tool which can automate the configuration of all the systems. With ansible a small team of system administrator can write…

Read More

TOP 65+ INTERVIEW QUESTIONS FOR ANSIBLE

Ansible most asked FAQ’s and interview questions:- Q1) what is Ansible? Ansible is developed in Python language. It is a software tool. It is useful while deploying…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x