Blockinfile looping overwrites even though the marker is differnent

11 views
Skip to first unread message

rcst.e...@gmail.com

unread,
May 25, 2017, 11:56:36 AM5/25/17
to Ansible Project
Hi all,

I am trying to insert a block of lines via Blockinfile module and it is overwriting the previous change even though I am using different marker.

I have configured the code like below:

----------
- name: update zones on master nodes
  blockinfile:
    dest: /etc/icinga2/zones.conf
    backup: yes
    marker: "// {mark} inserted {{ item[0] }}"
    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[1] }}"
  vars:
    ansible_become_pass: "{{ hostvars[item[1]].ansible_become_pass }}"
  with_nested:
    - "{{ groupname }}"
    - "{{ groups['icinga2-master'] }}"
  when: inventory_hostname == groups[groupname][0]
----------

And my inventory files is like below:

----------
[icinga2-master]
rcstmon01
rcstmon02

[icinga2-satellite-rcst]
bnemon01
bnemon02

[icinga2-satellite-test]
bnetest01

[icinga2-satellite-rcst:vars]
groupname=icinga2-satellite-rcst

[icinga2-satellite-test:vars]
groupname=icinga2-satellite-test

[icinga2-satellite:children]
icinga2-satellite-rcst
icinga2-satellite-test

[icinga2-cluster:children]
icinga2-master
icinga2-satellite
----------

When I run the playbook with -vvv option, I can see the correct contents are show as stdout but when I check the resulting file, only the last change is shown. Is there any way I can add blocks without overwriting? Shouldn't it stop overwriting when different marker is set? Thank you.
Reply all
Reply to author
Forward
0 new messages