---
- block:
  - name: Update /etc/hosts with freeipa's details
    become: yes
    lineinfile:
        dest: "/etc/hosts"
        line: "{{ freeipa_node_ipaddress }} {{ freeipa_node }}.{{ freeipa_domain }} {{ freeipa_node }}"
        state: present

  - name: set IdM server to be the nameserver if multiple domains
    become: yes
    copy:
        dest: "/usr/lib/systemd/resolv.conf"
        content: |
            search {{ freeipa_cloud_domain }} {{ freeipa_domain }}
            nameserver {{ freeipa_node_ipaddress }}
    when: freeipa_cloud_domain != freeipa_domain

  - name: set IdM server to be the nameserver if single domain
    become: yes
    copy:
        dest: "/usr/lib/systemd/resolv.conf"
        content: |
            search {{ freeipa_cloud_domain }}
            nameserver {{ freeipa_node_ipaddress }}
    when: freeipa_cloud_domain == freeipa_domain

  - name: Make systemd resolv.conf immutable
    become: yes
    file:
      path: /usr/lib/systemd/resolv.conf
      owner: root
      group: root
      mode: '0644'
      attributes: +i

  - name: Create a symbolic link of systemd resolv.conf
    become: yes
    file:
        src: "/usr/lib/systemd/resolv.conf"
        dest: "/etc/resolv.conf"
        owner: root
        group: root
        state: link
        force: yes

  delegate_to: "{{ freeipa_undercloud_node }}"

---
- block:
  - name: Update /etc/hosts with freeipa's details
    become: yes
    lineinfile:
        dest: "/etc/hosts"
        line: "{{ freeipa_node_ipaddress }} {{ freeipa_node }}.{{ freeipa_domain }} {{ freeipa_node }}"
        state: present

  - name: set IdM server to be the nameserver if multiple domains
    become: yes
    copy:
        dest: "/etc/resolv.conf"
        content: |
            search {{ freeipa_cloud_domain }} {{ freeipa_domain }}
            nameserver {{ freeipa_node_ipaddress }}
    when: freeipa_cloud_domain != freeipa_domain

  - name: set IdM server to be the nameserver if single domain
    become: yes
    copy:
        dest: "/etc/resolv.conf"
        content: |
            search {{ freeipa_cloud_domain }}
            nameserver {{ freeipa_node_ipaddress }}
    when: freeipa_cloud_domain == freeipa_domain

  - name: Set 'dns=none' in /etc/NetworkManager/NetworkManager.conf
    become: true
    ini_file:
        path: /etc/NetworkManager/NetworkManager.conf
        state: present
        no_extra_spaces: true
        section: main
        option: dns
        value: none
        backup: true

  #Always reload NetworkManager to load the manual changes in resolv.conf
  - name: Reload NetworkManager
    become: true
    service:
        name: NetworkManager
        state: reloaded

  delegate_to: "{{ freeipa_undercloud_node }}"

Stop network manager from updating resolv.conf and drop immutable hacks
Stop network manager from updating resolv.conf and drop immutable hacks

- make sure dns=none is always set for Network manager
- remove the symlink pointing to /usr/lib/systemd/resolv.conf which
  would cause systemd-resolved to get involved in mode 3
- always reload NetworkManager to prevent NetworkManager to remove any
  manual changes in resolv.conf upon quitting before host reboot

Change-Id: Ibc21cbd697fce96fca68fadafb5abc183c86905e
