main.yml 835 B

123456789101112131415161718192021222324252627282930
  1. ---
  2. - name: Add name/IP to hosts file
  3. lineinfile:
  4. dest: /etc/hosts
  5. regexp: '^{{ ansible_default_ipv4.address }}.*{{ ansible_hostname }}\.ansible\.kurs.*{{ ansible_hostname }}'
  6. line: '{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.ansible.kurs {{ ansible_hostname }}'
  7. backup: yes
  8. - name: Clean/remove 127.0.1.1
  9. lineinfile:
  10. dest: /etc/hosts
  11. regexp: '127.0.1.1.*{{ ansible_hostname }}'
  12. state: absent
  13. backup: yes
  14. - name: Clean/remove 127.0.0.1 ... Hostname
  15. lineinfile:
  16. dest: /etc/hosts
  17. regexp: '127.0.0.1.*{{ ansible_hostname }}'
  18. state: absent
  19. backup: yes
  20. - name: Ensure 127.0.0.1 localhost
  21. lineinfile:
  22. dest: /etc/hosts
  23. regexp: '127.0.0.1.*localhost'
  24. line: '127.0.0.1 localhost localhost.localdomain # from Ansible'
  25. insertbefore: BOF
  26. backup: yes