# block in file with loop

**URL:** <https://forum.ansible.com/t/block-in-file-with-loop/21256>\
**Category:** Ansible Project\
**Created:** [April 25, 2016, 9:24am UTC](https://forum.ansible.com/t/block-in-file-with-loop/21256 "2016-04-25T09:24:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bala\_krishna](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@bala\_krishna](https://forum.ansible.com/u/bala_krishna)\
**Post date:** [April 25, 2016, 9:24am UTC](https://forum.ansible.com/t/block-in-file-with-loop/21256/1 "2016-04-25T09:24:09Z")

</div>

Hi,

I am trying to write ansible playbook for Nagios client installation and configuration.

- name: untar Plugin Zip file to libexec directory  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: mount | grep -v "rootLV" | grep ext4 | awk '{print $3}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: dirlist

- name: create Nagios Host ServiceConfig file  
&nbsp;&nbsp;&nbsp;blockinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /scripts/{{ ansible\_hostname }}\_svc.cfg  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;block: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;define service{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host\_name {{ ansible\_hostname }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service\_description {{ item }} filesystem  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check\_command check\_nrpe!check\_disk\_boot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max\_check\_attempts 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;normal\_check\_interval 5  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retry\_check\_interval 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check\_period 24x7  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notification\_interval 120  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notification\_period 24x7  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notification\_options w,u,c,r  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contact\_groups touchpoint  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notifications\_enabled 1}

&nbsp;&nbsp;with\_items: "{{dirlist.stdout\_lines}}"

I was trying to create service configuration file using above playbook but it's been failing. Can someone guide me on this

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [April 25, 2016, 3:32pm UTC](https://forum.ansible.com/t/block-in-file-with-loop/21256/2 "2016-04-25T15:32:19Z")

</div>

Care to tell us the exact error? "failing" can mean lots of things.

Does "ansible-playbook --syntax-check yourplaybook.yml" bring any more  
details that are helpful?

Johannes
