Ansible-YAML Syntax and Concept

Ansible YAML  |Ansible uses YAML language to make ansible playbook through which control machine is executed automation tasks on remote machine.Yaml language is straightforward language and straightforward for the human being,but we should know yaml Syntax in all respects unmistakably .We use YAML on the grounds that it is simpler for people to peruse and compose than other format like XML or JSON.


YAML Syntax


To define Yaml syntax we should know the below points.

 YAML file must starts with “---” and should  ends with “...”.

YAML supports  “|” to denote  newlines while showing multiple lines and “>” to suppress newlines while showing multiple lines.

YAML Concept


YAML utilizes basic key-value pair to speak to the data. 

We should maintain a gap  among : and value.

Employee record for an example:

---
rahul:
   name: rahul sharma
   empNo: 120
   sex: male

How to represent list inside directory


We can also represent list within directory using yaml language.

For an example:

---
rahul:
   name: rahul sharma
   empNo: 120
   sex: male
   dept:
   - sales
   - hr
   - marketing

How to represent list using yaml


All members of lists are starting at same level and starting with “-”
Note − There should be space after “_”.
To represent list using yaml let take an example

For an Example:

---
Games:
   - Cricket
   - Football
   - polo

Create list for many dictionaries


We can create list for many directories using yaml language. 

YAML concept,Ansible,yaml syntax
ansible YAML Syntax and Concept

---
- rahul:
   name: rahul sharma
   empNo: 120
   sex: male
   dept:
   - sales
   - hr
   - marketing

- rahim:
   name: rahim kumar
   empNo: 130
   sex: male
   dept:
   - finance
   - it
 ...


If this article is helpful to know about Ansible YAML and yaml syntax please share this article.
SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments: