# yml indentation quirkness

**URL:** <https://forum.ansible.com/t/yml-indentation-quirkness/21160>\
**Category:** Ansible Project\
**Created:** [April 14, 2016, 6:22am UTC](https://forum.ansible.com/t/yml-indentation-quirkness/21160 "2016-04-14T06:22:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Kieu1](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Steve\_Kieu1](https://forum.ansible.com/u/Steve_Kieu1)\
**Post date:** [April 14, 2016, 6:22am UTC](https://forum.ansible.com/t/yml-indentation-quirkness/21160/1 "2016-04-14T06:22:53Z")

</div>

Hi Team,

I have a bug in the code that is simple to fix but hard to find out. It took me almost 30 minutes to see but it is due to the fact that yml indentation syntax quirkness!

Lets see the block below

- block:
- name: disable sssd service for non production nodes by all means  
service: name=sssd state=stopped enabled=no  
ignore\_errors: True
- shell: “chmod -x /init.d/sssd.sh || true”
- shell: “kill `ps -ef|grep '/usr/sbin/sssd' | grep -v grep | awk '{print $2}'` || true”
- name: remove the sss service from nsswitch.conf  
replace: dest=/etc/nsswitch.conf regexp=‘^(.\*) sss$’ replace=‘\1’ backup=yes  
when: host\_type not in [‘production’, ‘livepreview’]

You see the fact that after the - it _must_ be a space (right?) so the when condition allied to the whole block needs to be match with exactly the b of the block. Or course if I set tab width to 2 it would be it if the start of the line press tab, but if I set tab to any other size, it wont, I need to align it exactly two spaces!

After a long block the alignment does not look good anymore and harder to spot out indentation error.

Can I do something like -[TAB]block and from that only use TAB so it does not matter TAB size, I can always use tab for indentation?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [April 14, 2016, 7:29am UTC](https://forum.ansible.com/t/yml-indentation-quirkness/21160/2 "2016-04-14T07:29:09Z")

</div>

You're better off wth spaces than tabs:

&nbsp;&nbsp;&nbsp;&nbsp;[http://yaml.org/spec/current.html#id2519916](http://yaml.org/spec/current.html#id2519916)

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [April 14, 2016, 1:27pm UTC](https://forum.ansible.com/t/yml-indentation-quirkness/21160/3 "2016-04-14T13:27:10Z")

</div>

You may be able to have your text editor insert spaces when you hit the  
tab key, if that's what you want. Google turned up recommendations for vi  
and Emacs, or search for your editor of choice.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
