2014-08-26 21:36:08 +00:00
|
|
|
---
|
2024-01-13 16:08:19 +00:00
|
|
|
- name: Include dist_vars
|
|
|
|
ansible.builtin.include_tasks: dist_vars.yml
|
|
|
|
- name: Include install tasks
|
|
|
|
ansible.builtin.include_tasks: install.yml
|
2014-08-26 21:36:08 +00:00
|
|
|
|
2015-03-29 20:56:46 +00:00
|
|
|
- name: Get list of nameservers configured in /etc/resolv.conf
|
2024-01-13 16:08:19 +00:00
|
|
|
ansible.builtin.shell: set -o pipefail && grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
|
2015-03-29 20:56:46 +00:00
|
|
|
register: dhcpd_register_nameservers
|
2024-01-13 16:08:19 +00:00
|
|
|
changed_when: false
|
2015-03-29 20:56:46 +00:00
|
|
|
when: dhcpd_mode == 'server'
|
2024-01-13 16:08:19 +00:00
|
|
|
check_mode: false
|
2015-03-29 20:56:46 +00:00
|
|
|
|
|
|
|
- name: Convert list of nameservers to Ansible list
|
2024-01-13 16:08:19 +00:00
|
|
|
ansible.builtin.set_fact:
|
2015-08-29 18:01:23 +00:00
|
|
|
dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}"
|
2015-03-29 20:56:46 +00:00
|
|
|
when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout)
|
|
|
|
|
2014-08-26 21:36:08 +00:00
|
|
|
- name: Configure DHCP server
|
2024-01-13 16:08:19 +00:00
|
|
|
ansible.builtin.template:
|
2021-10-24 18:54:44 +00:00
|
|
|
src: "etc/dhcp/dhcpd.conf.j2"
|
|
|
|
dest: "/{{ item }}"
|
|
|
|
owner: "root"
|
|
|
|
group: "root"
|
|
|
|
mode: "0644"
|
2017-09-20 23:56:00 +00:00
|
|
|
with_items: "{{ dhcpd_templates }}"
|
2021-10-24 18:54:44 +00:00
|
|
|
notify: ["Restart dhcp server"]
|
2015-04-07 11:03:48 +00:00
|
|
|
register: dhcpd_register_config
|
2015-03-27 13:32:44 +00:00
|
|
|
when: dhcpd_mode == 'server'
|
2014-08-26 21:36:08 +00:00
|
|
|
|
2015-04-07 11:03:48 +00:00
|
|
|
- name: Make sure that included files exist
|
2024-01-13 16:08:19 +00:00
|
|
|
ansible.builtin.file:
|
2021-10-24 18:54:44 +00:00
|
|
|
path: "{{ item }}"
|
|
|
|
state: "touch"
|
|
|
|
owner: "root"
|
|
|
|
group: "root"
|
|
|
|
mode: "0644"
|
|
|
|
with_items: "{{ dhcpd_includes }}"
|
|
|
|
notify: ["Restart dhcp server"]
|
2015-04-07 11:03:48 +00:00
|
|
|
when: ((item is defined and item) and dhcpd_mode == 'server' and
|
2021-10-24 18:54:44 +00:00
|
|
|
(dhcpd_register_config is defined and dhcpd_register_config.changed))
|
2015-04-07 11:03:48 +00:00
|
|
|
|
2015-03-29 19:13:24 +00:00
|
|
|
- name: Make sure that IPv6 lease file exists
|
2024-01-13 16:08:19 +00:00
|
|
|
ansible.builtin.command: touch /var/lib/dhcp/dhcpd6.leases creates=/var/lib/dhcp/dhcpd6.leases
|
2015-03-29 19:13:24 +00:00
|
|
|
when: dhcpd_ipversion == '6'
|
|
|
|
|
2024-01-13 16:08:19 +00:00
|
|
|
- name: Include dhcp-probe
|
|
|
|
ansible.builtin.include_tasks: dhcp-probe.yml
|
2015-03-30 11:34:53 +00:00
|
|
|
when: dhcpd_probe|d() and dhcpd_probe
|
2021-11-14 15:49:54 +00:00
|
|
|
|
2024-01-13 16:08:19 +00:00
|
|
|
- name: Enable DHCP4
|
|
|
|
ansible.builtin.service:
|
2021-11-14 15:49:54 +00:00
|
|
|
name: dhcpd4
|
|
|
|
state: started
|
2024-01-13 16:08:19 +00:00
|
|
|
enabled: true
|