yml indentation quirkness

37 views
Skip to first unread message

Steve Kieu

unread,
Apr 14, 2016, 2:22:53 AM4/14/16
to Ansible Project
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? 

Dick Davies

unread,
Apr 14, 2016, 3:29:15 AM4/14/16
to ansible list
You're better off wth spaces than tabs:

http://yaml.org/spec/current.html#id2519916
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c65099be-0cfc-479d-bef7-0e5491eabeb5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Josh Smift

unread,
Apr 14, 2016, 9:27:24 AM4/14/16
to ansible...@googlegroups.com
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.

-Josh (j...@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.
Reply all
Reply to author
Forward
0 new messages