Blockinfile indentation

4,529 views
Skip to first unread message

Joanna Delaporte

unread,
May 26, 2016, 4:33:15 PM5/26/16
to Ansible Project
I am using blockinfile to write lines to a vars file that includes a few different layers of indentation. How do I make sure the indentation levels are maintained correctly using the block | statement?

Thanks!
Joanna

Alli

unread,
Jul 28, 2016, 2:32:40 PM7/28/16
to Ansible Project
You can use a block indentation indicator http://www.yaml.org/spec/1.2/spec.html#id2793979

e.g:

- blockinfile:
    dest: /etc/postfix/master.cf
    insertafter: "^submission inet n       -       n       -       -       smtpd$"
    block: |2
        -o syslog_name=postfix/submission
        -o ...

The number specifies how many spaces there are that are meaningful, so there's a total of 8 leading spaces, 6 of which are yaml indentation and 2 for the block itself. 

From this excellent answer: http://stackoverflow.com/a/21699210

Joanna Delaporte

unread,
Jul 29, 2016, 4:01:40 PM7/29/16
to Ansible Project
Thanks!

ZillaYT

unread,
Sep 27, 2016, 2:40:22 PM9/27/16
to Ansible Project
This seems to be broken in Ansible 2.1.1.0.

Jonathan Doig

unread,
Apr 20, 2017, 10:29:47 AM4/20/17
to Ansible Project
Block indentation indicator still broken in ansible 2.3 :(


Jonathan
Reply all
Reply to author
Forward
0 new messages