ansible-dhcpd/tasks/main.yml

73 lines
2.2 KiB
YAML
Raw Normal View History

---
- name: Configure DHCP relay in debconf
debconf:
name: 'isc-dhcp-relay'
question: 'isc-dhcp-relay/{{ item.key }}'
vtype: 'string'
value: '{{ item.value }}'
with_dict:
servers: '{{ dhcpd_relay_servers | join(" ") }}'
interfaces: '{{ dhcpd_relay_interfaces | join(" ") }}'
options: '{{ dhcpd_relay_options }}'
register: dhcpd_register_relay_debconf
when: dhcpd_mode == 'relay'
2015-03-27 09:50:21 +00:00
- name: Install DHCP packages
apt:
name: '{{ item }}'
state: 'present'
install_recommends: False
with_flattened:
- '{{ dhcpd_base_packages_map[dhcpd_mode] }}'
- [ '{{ "dhcp-probe" if (dhcpd_probe|d() and dhcpd_probe) else [] }}' ]
- name: Reconfigure ISC DHCP relay
command: dpkg-reconfigure --frontend=noninteractive isc-dhcp-relay
notify: [ 'Restart isc-dhcp-relay' ]
when: dhcpd_register_relay_debconf|d() and dhcpd_register_relay_debconf.changed
- name: Get list of nameservers configured in /etc/resolv.conf
shell: grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
register: dhcpd_register_nameservers
changed_when: False
when: dhcpd_mode == 'server'
2016-04-08 10:03:33 +00:00
always_run: yes
- name: Convert list of nameservers to Ansible list
set_fact:
dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}"
when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout)
- name: Configure DHCP server
2015-03-27 09:50:21 +00:00
template:
src: '{{ item }}.j2'
dest: '/{{ item }}'
owner: 'root'
group: 'root'
mode: '0644'
with_items: [ 'etc/default/isc-dhcp-server', 'etc/dhcp/dhcpd.conf' ]
2015-03-27 09:50:21 +00:00
notify: [ 'Restart isc-dhcp-server' ]
register: dhcpd_register_config
when: dhcpd_mode == 'server'
- name: Make sure that included files exist
file:
path: '{{ item }}'
state: 'touch'
owner: 'root'
group: 'root'
mode: '0644'
with_items: '{{ dhcpd_includes }}'
notify: [ 'Restart isc-dhcp-server' ]
when: ((item is defined and item) and dhcpd_mode == 'server' and
(dhcpd_register_config is defined and dhcpd_register_config.changed))
- name: Make sure that IPv6 lease file exists
command: touch /var/lib/dhcp/dhcpd6.leases creates=/var/lib/dhcp/dhcpd6.leases
when: dhcpd_ipversion == '6'
- include: dhcp-probe.yml
when: dhcpd_probe|d() and dhcpd_probe