How to create Ansible Playbooks

What is a playbook in Ansible ?

  • It is a set of instructions which define what ansible need to do.
  • It can be as simple as a set of commands on a particular server or as complex as deploying application on hundreds of VMs.
  • It reads a particular format of instructions which is written in YAML.

 


In below screenshot, it’s shown how modules are formatted in a Playbook. We will be learning about Modules in coming blogs.


There are 2 ways of executing ansible commands :

  1. With ansible playbook
  2. Without ansible playbook

In below screenshot, it’s shown how you can execute ansible commands with and without ansible playbook

 

  • Ansible creates a group by default : all – that contains all the hosts which are mentioned in playbookfile.

    Example :

 

  • The extension of Playbook can be either .yml or .yaml

 

In above screenshot, we have created a playbook with name playbook-pingtest.yaml in which we have mentioned all hosts in the host category so that it will read all the hosts which are mentioned in inventory file. In task, we have mentioned to perform a Ping Test on all the hosts.

In execution command, we have ran ansible-playbook command using other parameters.

 

Check out – How to install AKS with internal ingress controller and API Management – Part II

 

Leave a Reply

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