Playbooks are the files where Ansible code is written in YAML/YML format. Playbooks are Ansible’s deployment, configuration, and orchestration language. They’ll describe a rule you would like your remote systems to enforce/follow, or a collection of steps during a general IT method.
Basically, ansible playbooks are accustomed for managing configurations and deployment to remote machines of an application. In an additional advanced level, it will sequence multi-tier rollouts involving rolling updates, and may delegate actions to alternative hosts, interacting with observance servers.
Each playbook is an aggregation of one or many plays in it. They are structured using Plays.
Create a Playbook
Let us start by writing a sample YAML file.
--- Name: install and configure DB Hosts: salesforcedrillersserver become: yes vars: mysql_db_port_value : 3306 Tasks: -name: Install the mysql yum: <code to install the DB> -name: Ensure the installed service is enabled and running service: name: <your service name>
Basic syntax of a playbook is shown using above sample Playbook. Save the above content in a file named as test.yml
The Different YAML Tags
- Name : This tag indicates the name of the Ansible playbook.
- Hosts: This tag specifies the lists of hosts or host groups against which we want to run the task, and this hosts field/tag is mandatory.
- Tasks: A tasks field contains the name of the task. A module i.e. a piece of code is internally linked by each task.A module which must executed with arguments required for execution of a module.