homelab-server/ansible/configure_dns.yml

25 lines
725 B
YAML

---
- name: Point VM DNS to central FreeIPA server
hosts: control, web, media
become: true
tasks:
- name: Get current DNS settings
ansible.builtin.command:
cmd: nmcli -g ipv4.dns connection show "cloud-init ens3"
register: current_dns
changed_when: false
- name: Set DNS servers to FreeIPA
ansible.builtin.command:
cmd: nmcli con mod "cloud-init ens3" ipv4.dns "172.30.1.100 1.1.1.1"
when: (current_dns.stdout | trim) != "172.30.1.100,1.1.1.1"
changed_when: true
notify: Restart network connection
handlers:
- name: Restart network connection
ansible.builtin.command:
cmd: nmcli con up "cloud-init ens3"
changed_when: false