ansible-role-dhcpd/tasks/main.yml

63 lines
1.6 KiB
YAML
Raw Normal View History

2022-02-21 21:35:01 +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"
- name: Include OS-specific variables
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
2022-02-21 21:35:01 +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 }}"
- 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
- name: Cleanup cache files
notify: Restart dhcpd
2022-02-21 21:35:01 +00:00
block:
- name: Check if cache dir exists
ansible.builtin.stat:
2022-02-21 21:35:01 +00:00
path: "{{ dhcpd_cache_directory }}"
register: cache_stats
- 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
- 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
- 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
- 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 }}"