Ansible Playbook

Ansible Playbook

Playbooks are the files where Ansible code is written. Playbooks are written in YAML format. YAML stands for Yet Another Markup Language. It is human-readable data serialization language and commonly used for configuration files.

Playbook is like a file where you write codes consist of vars, tasks, handlers, files, templates and roles.

Each playbook is composed of one or more modules in a list and Module is a collection of configuration files.




Playbooks are divided into many sections such as -

Target Section = Defines that host against which playbooks task has to be executed



Variable Section = variables are names used to hold one or more values

Task Section = List of all modules that we need to run in order.

YAML (Yet another Markup Language)


For ansible, nearly every YAML files start with a list. Each item in the list is a list of key-value pairs commonly call a dictionary. 

All YAML files have to begin with "---" and end with "..."

All members of a listed line must begin with the same indentation level starting with "-"

for example:

--- # A list of fruits
    fruits:
        - Apple
        - Mango
        - Banana
        - Pineapple
        - Grapes



A dictionary is represented in a simple key: value form

for example:

--- # A list of customer
- customer:
        name: Rakesh
        job: Trainer
        skills: Ansible
        exp: 7 years

Extension for playbook files is .yml

Note:- There should be space between : and value

[user@ip]# vi target.yml

--- # First Test playbook
    - hosts: demo
      user: ansible
      become: yes
      connection: ssh
      gather_facts: yes

now to execute this playbook

[user@ip]# ansible-playbook target.yml








Share:

0 comments

Please leave your comments...... Thanks