2022-02-21 21:35:01 +00:00
|
|
|
---
|
|
|
|
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Check if at least one subnet is defined
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.assert:
|
2022-02-21 21:35:01 +00:00
|
|
|
that:
|
|
|
|
- dhcpd_subnets | length > 0
|
|
|
|
fail_msg: "No subnet defined"
|
|
|
|
|
2022-12-28 21:03:49 +00:00
|
|
|
- name: Include OS-specific variables
|
2023-02-12 13:39:48 +00:00
|
|
|
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
|
2022-02-21 21:35:01 +00:00
|
|
|
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Install dhcpd with dependencies
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.package:
|
2022-02-21 21:35:01 +00:00
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- "{{ dhcpd_package_names }}"
|
|
|
|
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Create dhcpd config
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.template:
|
2022-02-21 21:35:01 +00:00
|
|
|
src: "dhcpd.conf.j2"
|
|
|
|
dest: "{{ dhcpd_main_config }}"
|
|
|
|
owner: "{{ dhcpd_unix_user }}"
|
|
|
|
group: "{{ dhcpd_unix_group }}"
|
2023-02-26 21:22:32 +00:00
|
|
|
mode: "0644"
|
2022-02-21 21:35:01 +00:00
|
|
|
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Cleanup cache files
|
|
|
|
notify: Restart dhcpd
|
2022-02-21 21:35:01 +00:00
|
|
|
block:
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Check if cache dir exists
|
|
|
|
ansible.builtin.stat:
|
2022-02-21 21:35:01 +00:00
|
|
|
path: "{{ dhcpd_cache_directory }}"
|
|
|
|
register: cache_stats
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Remove cache dir
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.file:
|
2022-02-21 21:35:01 +00:00
|
|
|
path: "{{ dhcpd_cache_directory }}"
|
|
|
|
state: absent
|
|
|
|
when: cache_stats.stat.exists
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Create cache dir
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.file:
|
2022-02-21 21:35:01 +00:00
|
|
|
path: "{{ dhcpd_cache_directory }}"
|
|
|
|
owner: "{{ dhcpd_unix_user }}"
|
|
|
|
group: "{{ dhcpd_unix_group }}"
|
2023-02-26 21:22:32 +00:00
|
|
|
mode: "0755"
|
2022-02-21 21:35:01 +00:00
|
|
|
state: directory
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Create cache files
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.file:
|
2022-02-21 21:35:01 +00:00
|
|
|
path: "{{ dhcpd_cache_directory }}/{{ item }}"
|
|
|
|
owner: "{{ dhcpd_unix_user }}"
|
|
|
|
group: "{{ dhcpd_unix_group }}"
|
2023-02-26 21:22:32 +00:00
|
|
|
mode: "0644"
|
2022-02-21 21:35:01 +00:00
|
|
|
state: touch
|
|
|
|
with_items:
|
|
|
|
- dhcpd.leases
|
|
|
|
|
2023-02-12 13:39:48 +00:00
|
|
|
- name: Start and enable dhcpd
|
2023-02-08 17:22:40 +00:00
|
|
|
ansible.builtin.systemd:
|
2022-02-21 21:35:01 +00:00
|
|
|
name: "{{ item }}"
|
|
|
|
state: started
|
2023-02-08 17:22:40 +00:00
|
|
|
enabled: true
|
2022-02-21 21:35:01 +00:00
|
|
|
with_items:
|
2023-02-08 17:22:40 +00:00
|
|
|
- "{{ dhcpd_service_name }}"
|