ansible-role-dhcpd/tasks/main.yml

62 lines
1.4 KiB
YAML
Raw Normal View History

2022-02-21 21:35:01 +00:00
---
- name: check if at least one subnet is defined
assert:
that:
- dhcpd_subnets | length > 0
fail_msg: "No subnet defined"
- name: include special distribution-dependent variables
include_vars: "{{ ansible_os_family }}.yml"
- name: install dhcpd with dependencies
package:
name: "{{ item }}"
state: present
with_items:
- "{{ dhcpd_package_names }}"
- name: create dhcpd config
template:
src: "dhcpd.conf.j2"
dest: "{{ dhcpd_main_config }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: 0644
- name: cleanup cache files
block:
- name: check if cache dir exists
stat:
path: "{{ dhcpd_cache_directory }}"
register: cache_stats
- name: remove cache dir
file:
path: "{{ dhcpd_cache_directory }}"
state: absent
when: cache_stats.stat.exists
- name: create cache dir
file:
path: "{{ dhcpd_cache_directory }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: 0755
state: directory
- name: create cache files
file:
path: "{{ dhcpd_cache_directory }}/{{ item }}"
owner: "{{ dhcpd_unix_user }}"
group: "{{ dhcpd_unix_group }}"
mode: 0644
state: touch
with_items:
- dhcpd.leases
notify: restart dhcpd
- name: start and enable dhcpd
systemd:
name: "{{ item }}"
state: started
enabled: yes
with_items:
- "{{ dhcpd_service_name }}"