HowTo Write Ansible Playbook for the First Time Guide

Most of the articles from Ansible says it’s very simple to write and play an playbook. But i tried to write an simple playbooks and run it’s shows me an syntax error what..!! All the playbook is well written and nothing wrong in it. But you know i missed out an alignment it’s failed to execute. Let’s see HowTo Write Ansible Playbook for the first Time Guide.

HowTo Write Ansible Playbook

ansible playbook writing

ansible playbook writing

If you see at above playbook alignment is exactly correct and when i execute it it runs perfect

executed playbook successfully

executed playbook successfully

Let’s see the same playbook without proper alignment it shows an syntax error

Yaml syntax error while loading

Yaml syntax error while loading

shown above is the same playbook as we executed previously, what changed is only i have added few spaces in hosts and tasks lines and it failed to execute. 

Do remember to write the playbook with right alignment or else you will end up with YAML syntax errors

A few rules you need to follow is, when you want include : (colon) in statement you have to enable quotations (” “) from start to end shown example is below

-name: Incorrect: Method: to Write
- name: "Testing: Production and UAT"

you can still write paths as like

windows_path: c:\window

to tell you further on writing ansible variables and there examples

content: "{{ correct }}"
variable: "{{ correct }} Testing"
contnt: "{{ Wrong }}"Testing

That’s it. HowTo Write Ansible Playbook, there are many modules you can explore to write Ansible playbooks. 

Related Articles

Create Multiple Users with Single Linux command

For more about YAML Language

Thanks for your wonderful Support and Encouragement

blank

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

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