--- - name: etchosts-customizations | Add entries to /etc/hosts when: custom_etc_hosts_entries | length > 0 tags: - etchosts block: - name: etchosts-customizations | Add custom entries to /etc/hosts ansible.builtin.blockinfile: path: /etc/hosts marker_begin: 'ansible_etchosts_customizations_start' marker_end: 'ansible_etchosts_customizations_end' marker: "# {mark} hosts entries managed by ansible" block: "{{ custom_etc_hosts_entries }}" state: present - name: etchosts-customizations | Remove entries from /etc/hosts when: custom_etc_hosts_entries | length == 0 tags: - etchosts block: - name: etchosts-customizations | Remove custom entries from /etc/hosts ansible.builtin.blockinfile: path: /etc/hosts marker_begin: 'ansible_etchosts_customizations_start' marker_end: 'ansible_etchosts_customizations_end' marker: "# {mark} hosts entries managed by ansible" block: "{{ custom_etc_hosts_entries }}" state: absent - name: etchosts-customizations | Additional custom entries to /etc/hosts when: custom_etc_hosts_entries_adjunct | length > 0 tags: - etchosts block: - name: etchosts-customizations | Additional custom entries to /etc/hosts ansible.builtin.blockinfile: path: /etc/hosts marker_begin: 'ansible_etchosts_adjunct_start' marker_end: 'ansible_etchosts_adjunct_end' marker: "# {mark} additional hosts entries managed by ansible" block: "{{ custom_etc_hosts_entries_adjunct }}" state: present - name: etchosts-customizations | Remove entries from /etc/hosts when: custom_etc_hosts_entries_adjunct | length == 0 tags: - etchosts block: - name: etchosts-customizations | Remove the additional custom entries from /etc/hosts ansible.builtin.blockinfile: path: /etc/hosts marker_begin: 'ansible_etchosts_adjunct_start' marker_end: 'ansible_etchosts_adjunct_end' marker: "# {mark} additional hosts entries managed by ansible" block: "{{ custom_etc_hosts_entries_adjunct }}" state: absent