# Blockinfile indentation

**URL:** <https://forum.ansible.com/t/blockinfile-indentation/21581>\
**Category:** Ansible Project\
**Created:** [May 26, 2016, 8:33pm UTC](https://forum.ansible.com/t/blockinfile-indentation/21581 "2016-05-26T20:33:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [May 26, 2016, 8:33pm UTC](https://forum.ansible.com/t/blockinfile-indentation/21581/1 "2016-05-26T20:33:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alli](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Alli](https://forum.ansible.com/u/Alli)\
**Post date:** [July 28, 2016, 10:54am UTC](https://forum.ansible.com/t/blockinfile-indentation/21581/2 "2016-07-28T10:54:40Z")

</div>

You can use a block indentation indicator [http://www.yaml.org/spec/1.2/spec.html#id2793979](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](http://stackoverflow.com/a/21699210)

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [July 29, 2016, 8:01pm UTC](https://forum.ansible.com/t/blockinfile-indentation/21581/3 "2016-07-29T20:01:39Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [September 27, 2016, 6:40pm UTC](https://forum.ansible.com/t/blockinfile-indentation/21581/4 "2016-09-27T18:40:22Z")

</div>

This seems to be broken in Ansible 2.1.1.0.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Doig](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@Jonathan\_Doig](https://forum.ansible.com/u/Jonathan_Doig)\
**Post date:** [April 20, 2017, 1:36am UTC](https://forum.ansible.com/t/blockinfile-indentation/21581/5 "2017-04-20T01:36:30Z")

</div>

Block indentation indicator still broken in ansible 2.3 ☹

Raised a new issue [#23777 YAML block indentation indicator not working in Ansible 2.3.0.0](https://github.com/ansible/ansible/issues/23777).

Jonathan
