Files
ansible-role-dhcpd/tasks/main.yaml
Markus Pesch d6cb0493dc
All checks were successful
Ansible Linter / ansible-lint (push) Successful in 17s
Lint Markdown files / markdown-lint (push) Successful in 5s
fix: replace deprecated INJECT_FACTS_AS_VARS
2026-01-05 10:33:59 +01:00

73 lines
1.9 KiB
YAML

---
- name: Check if at least one subnet is defined
ansible.builtin.assert:
that:
- dhcpd_subnets | length > 0
fail_msg: "No subnet defined"
- name: Include OS-specific variables
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts['distribution'] }}_{{ ansible_facts['architecture'] }}.yaml"
- "{{ ansible_facts['distribution'] }}.yaml"
- "{{ ansible_facts['os_family'] }}_{{ ansible_facts['architecture'] }}.yaml"
- "{{ ansible_facts['os_family'] }}.yaml"
- main.yaml
paths:
- vars
- name: Install dhcpd with dependencies
ansible.builtin.package:
name: "{{ item }}"
state: present
with_items:
- "{{ dhcpd_package_names }}"
- name: Create dhcpd config
ansible.builtin.template:
src: "dhcpd.conf.j2"
dest: "{{ dhcpd_main_config }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: "0644"
- name: Cleanup cache files
notify: Restart dhcpd
block:
- name: Check if cache dir exists
ansible.builtin.stat:
path: "{{ dhcpd_cache_directory }}"
register: cache_stats
- name: Remove cache dir
ansible.builtin.file:
path: "{{ dhcpd_cache_directory }}"
state: absent
when: cache_stats.stat.exists
- name: Create cache dir
ansible.builtin.file:
path: "{{ dhcpd_cache_directory }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: "0755"
state: directory
- name: Create cache files
ansible.builtin.file:
path: "{{ dhcpd_cache_directory }}/{{ item }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: "0644"
state: touch
with_items:
- dhcpd.leases
- name: Start and enable dhcpd
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
with_items:
- "{{ dhcpd_service_name }}"