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.
--
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/9233148c-0c2a-46d9-a0f2-4870003bc1e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.