# blockinfile:  content="{{ item.content }}" -- Making it pretty

**URL:** <https://forum.ansible.com/t/blockinfile-content-item-content-making-it-pretty/27070>\
**Category:** Ansible Project\
**Created:** [March 21, 2018, 9:03pm UTC](https://forum.ansible.com/t/blockinfile-content-item-content-making-it-pretty/27070 "2018-03-21T21:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 21, 2018, 9:03pm UTC](https://forum.ansible.com/t/blockinfile-content-item-content-making-it-pretty/27070/1 "2018-03-21T21:03:13Z")

</div>

I have the following which works. However, I would like to make the bash script code “pretty”. It is found under the “content” section of the with\_items. How can I do this?

`

- name: Ensure myscript.sh contains directory checks  
blockinfile:  
dest: “/home/{{ user.stdout }}/Scripts/myscript.sh”  
insertafter: “{{ item.regexp }}”  
marker: “## {mark} added by Ansible - {{ item.define }}”  
content: “{{ item.content }}”  
with\_items:
- { regexp: “^trap.\*exit\ 1._1\ 2\ 3\ ._”, define: “Check for /interface”, content: “if [-f /interface/]; then echo ‘The /interface/$NATU directory is missing, aborting!’; exit 1; fi” }
- { regexp: “^NATU.\*interface._grep\ natu._”, define: “Check for /interface/natu”, content: “if [-f /interface/$NATU]; then echo ‘The /interface/$NATU directory is missing, aborting!’; exit 1; fi” }

`

I want to have the content injected into the file as follows (which can easily be done without a loop, but I wish to do this within the loop):

`if [-f /interface/]; then`  
`echo 'The /interface/$NATU directory is missing, aborting!'`  
`exit 1`  
`fi`

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 22, 2018, 2:39pm UTC](https://forum.ansible.com/t/blockinfile-content-item-content-making-it-pretty/27070/2 "2018-03-22T14:39:34Z")

</div>

Have you tried using \n for the newline?

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 22, 2018, 4:01pm UTC](https://forum.ansible.com/t/blockinfile-content-item-content-making-it-pretty/27070/3 "2018-03-22T16:01:37Z")

</div>

That works! Thanks Kai.
