--- # tasks file for basics ## Modify /etc/hosts {{{ - name: Config host - Set 127.0.0.1 line in hosts file lineinfile: dest: /etc/hosts state: present regexp: "^{{ ansible_lo.ipv4.address }}" line: "{{ ansible_lo.ipv4.address }} {{ basics__hosts_localhost_content }}" backup: yes when: (basics__hosts_localhost_manage and ansible_lo.ipv4.address is defined) - name: Config host - Set ipv4 line in hosts file lineinfile: dest: /etc/hosts state: present regexp: "^{{ ansible_default_ipv4.address }}" line: "{{ ansible_default_ipv4.address }} {{ basics__hosts_ipv4_content }}" backup: yes when: (basics__hosts_ipv4_manage and ansible_default_ipv4.address is defined) - name: Config host - Purge other lines with hostname lineinfile: dest: /etc/hosts state: absent regexp: '^(?!({{ ansible_default_ipv4.address }})).*{{ ansible_hostname }}' backup: yes when: (basics__hosts_ipv4_manage and ansible_default_ipv4.address is defined) ## }}} ## Proxmox {{{ - name: Disable modification of /etc/hosts by Proxmox file: path: /etc/.pve-ignore.hosts state: '{{ "touch" if basics__proxmox_disable_hosts else "absent" }}' when: ansible_virtualization_type == "lxc" ## }}}