diff --git a/tasks/main.yml b/tasks/main.yml index c5b50a2..2f9e96b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,30 +1,27 @@ --- +- name: Detect domain name + set_fact: + domainname: "{{ ansible_dns.domain|default(False) or ansible_dns.search.0|default(False) or ansible_domain|default(False) or 'invalid'}}" + - name: Add name/IP to hosts file lineinfile: dest: /etc/hosts - regexp: '^{{ ansible_default_ipv4.address }}.*{{ ansible_hostname }}\.ansible\.kurs.*{{ ansible_hostname }}' - line: '{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.ansible.kurs {{ ansible_hostname }}' + regexp: '^{{ ansible_default_ipv4.address }}' + line: '{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ domainname }} {{ ansible_hostname }}' backup: yes - name: Clean/remove 127.0.1.1 lineinfile: dest: /etc/hosts - regexp: '127.0.1.1.*{{ ansible_hostname }}' - state: absent - backup: yes - -- name: Clean/remove 127.0.0.1 ... Hostname - lineinfile: - dest: /etc/hosts - regexp: '127.0.0.1.*{{ ansible_hostname }}' + regexp: '^127.0.1.1' state: absent backup: yes - name: Ensure 127.0.0.1 localhost lineinfile: dest: /etc/hosts - regexp: '127.0.0.1.*localhost' - line: '127.0.0.1 localhost localhost.localdomain # from Ansible' + regexp: '127.0.0.1' + line: '127.0.0.1 localhost localhost.localdomain' insertbefore: BOF backup: yes