I have the following task, which appears to execute successfully, but I end up with only one block (the last), while I actually want to have a block for each item entered into my file. How do I do that?
task:
- name: configure dns zone SRV records
delegate_to: 127.0.0.1
blockinfile:
dest: /home/ansible/env/playbooks/vars/bind.yml
state: present
backup: yes
insertafter: ‘^bind_zone_services:.*’
marker: “# {mark} ANSIBLE MANAGED SRV BLOCK”
block: | - name: “{{ item.name }}”
weight: 100
port: “{{ item.port }}”
target: “{{ ansible_hostname }}”
with_items: - { name: _ldap._tcp, port: 389 }
- { name: _kerberos._tcp, port: 88 }
- { name: _kerberos._udp, port: 88 }
- { name: _kerberos-master._tcp, port: 88 }
- { name: _kerberos-master._udp, port: 88 }
- { name: _kpasswd._tcp, port: 464 }
- { name: _kpasswd._udp, port: 464 }
- { name: _ntp._udp, port: 123 }
Result
- name: _ntp._udp
weight: 100
port: 123
target: hostname