--- - name: Include dist_vars ansible.builtin.include_tasks: dist_vars.yml - name: Include install tasks ansible.builtin.include_tasks: install.yml - name: Get list of nameservers configured in /etc/resolv.conf ansible.builtin.shell: set -o pipefail && grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}' register: dhcpd_register_nameservers changed_when: false when: dhcpd_mode == 'server' check_mode: false - name: Convert list of nameservers to Ansible list ansible.builtin.set_fact: dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}" when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout) - name: Configure DHCP server ansible.builtin.template: src: "etc/dhcp/dhcpd.conf.j2" dest: "/{{ item }}" owner: "root" group: "root" mode: "0644" with_items: "{{ dhcpd_templates }}" notify: ["Restart dhcp server"] register: dhcpd_register_config when: dhcpd_mode == 'server' - name: Make sure that included files exist ansible.builtin.file: path: "{{ item }}" state: "touch" owner: "root" group: "root" mode: "0644" with_items: "{{ dhcpd_includes }}" notify: ["Restart dhcp server"] when: ((item is defined and item) and dhcpd_mode == 'server' and (dhcpd_register_config is defined and dhcpd_register_config.changed)) - name: Make sure that IPv6 lease file exists ansible.builtin.command: touch /var/lib/dhcp/dhcpd6.leases creates=/var/lib/dhcp/dhcpd6.leases when: dhcpd_ipversion == '6' - name: Include dhcp-probe ansible.builtin.include_tasks: dhcp-probe.yml when: dhcpd_probe|d() and dhcpd_probe - name: Enable DHCP4 ansible.builtin.service: name: dhcpd4 state: started enabled: true