# code: language=ansible - name: Disable IPv6 Link Local Addressing ansible.builtin.lineinfile: path: /etc/systemd/network/10-cloud-init-eth0.network line: "{{ item.line }}" regexp: "{{ item.regexp }}" insertafter: '^\[Network\]$' firstmatch: true state: present loop: - line: LinkLocalAddressing=no regexp: '^LinkLocalAddressing\s*=\s*.*$' - line: IPv6LinkLocalAddressGenerationMode=none regexp: '^IPv6LinkLocalAddressGenerationMode\s*=\s*.*$' loop_control: label: "{{ item.line }}" notify: - Reboot - name: Disable ipv6 (all) ansible.posix.sysctl: name: "{{ item }}" reload: true state: present sysctl_set: true value: 1 loop: - net.ipv6.conf.all.disable_ipv6 - net.ipv6.conf.default.disable_ipv6 - net.ipv6.conf.lo.disable_ipv6 notify: - Reboot - name: Remove IPv6 localhost entries from /etc/hosts when: - (ipv4_only | default(false)) ansible.builtin.lineinfile: path: /etc/hosts line: "{{ item }}" state: absent loop: - '::1 localhost ip6-localhost ip6-loopback' - 'ff02::1 ip6-allnodes' - 'ff02::2 ip6-allrouters' notify: - Reboot - name: Flush handlers to trigger reboot if required ansible.builtin.meta: flush_handlers