Hi all,

I am having problem with looping Blockinfile module. It seems as if the 
first loop doesn't insert a new block into the target file. When I run the 
playbook the log shows that new block is inserted but it actually doesn't 
exist. When I run the same playbook again, the block is inserted. I am 
wondering if this is a bug or I am using the Ansible incorrectly.

The code is:

- name: update zones on master nodes
  blockinfile:
    dest: /etc/icinga2/zones.conf
    backup: yes
    marker: "// {mark} configuration for {{ groupname }}"
    block: |
      {% for host in groups[groupname] %}
      object Endpoint "{{ hostvars[host].ansible_fqdn }}" {
        host = "{{ hostvars[host].ansible_eth0.ipv4.address }}"
      }

      {% endfor %}

      object Zone "{{ groupname }}" {
        endpoints = [ {% for host in groups[groupname] -%} "{{ 
hostvars[host].ansible_fqdn }}" {%- if not loop.last %}, {% endif -%} {%- 
endfor %} ]

        parent = "master"
      }
    insertafter: 'satellite configuration'
  delegate_to: "{{ item }}"
  vars:
    ansible_become_pass: "{{ hostvars[item].ansible_become_pass }}"
  with_items:
    - "{{ groups['icinga2-master'] }}"
  when: inventory_hostname == groups[groupname][0]
  notify: restart icinga2 on master

Does this mean to do like that? When I run with -vvv option, I can see the 
correct blocks in stdout but it actually is not written to the target file. 
Could I please get some advice regarding this issue? Thanks a lot.


-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/47294382-3f27-420d-b03a-05667c6414c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to