- name: Comment out all ipv6 nameservers in /etc/resolv.conf
  lineinfile:
    path: /etc/resolv.conf
    regexp: '^(nameserver.*)$'
    line: '# \1'
    backrefs: yes

- name: Add ipv4 public nameservers
  lineinfile:
    path: /etc/resolv.conf
    line: 'nameserver 8.8.8.8'

- name: Check whether /etc/dhcp/ directory exists
  stat:
    path: /etc/dhcp
  register: dhcp_config_dir

- name: Preserve /etc/resolv.conf from updating by DHCP client
  lineinfile:
    path: /etc/dhcp/dhclient-enter-hooks
    create: true
    line: 'make_resolv_conf() { : ; }' # Override function, which generates resolv.conf
  when: dhcp_config_dir.stat.isdir is defined and dhcp_config_dir.stat.isdir

- name: Comment out all ipv6 nameservers in /etc/resolv.conf
  lineinfile:
    path: /etc/resolv.conf
    regexp: '^(nameserver.*)$'
    line: '# \1'
    backrefs: yes

- name: Add ipv4 public nameservers
  lineinfile:
    path: /etc/resolv.conf
    line: 'nameserver 8.8.8.8'

- name: Check whether /etc/dhcp/ directory exists
  stat:
    path: /etc/dhcp
  register: dhcp_config_dir

- name: Preserve /etc/resolv.conf from updating by DHCP client
  lineinfile:
    path: /etc/dhcp/dhclient-enter-hooks
    create: true
    line: 'make_resolv_conf() { : ; }' # Override function, which generates resolv.conf
    mode: 0755
  when: dhcp_config_dir.stat.isdir is defined and dhcp_config_dir.stat.isdir

Make dhcp client hook file executable
Make dhcp client hook file executable
