2014-08-26 21:36:08 +00:00
|
|
|
---
|
|
|
|
|
2015-03-27 13:32:44 +00:00
|
|
|
- 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
|
2015-03-30 11:34:53 +00:00
|
|
|
with_flattened:
|
2016-04-13 07:23:26 +00:00
|
|
|
- '{{ dhcpd_base_packages_map[dhcpd_mode] }}'
|
2015-03-30 11:34:53 +00:00
|
|
|
- [ '{{ "dhcp-probe" if (dhcpd_probe|d() and dhcpd_probe) else [] }}' ]
|
2015-03-27 13:32:44 +00:00
|
|
|
|
|
|
|
- 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
|
2014-08-26 21:36:08 +00:00
|
|
|
|
2015-03-29 20:56:46 +00:00
|
|
|
- name: Get list of nameservers configured in /etc/resolv.conf
|
2015-08-29 18:01:23 +00:00
|
|
|
shell: grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
|
2015-03-29 20:56:46 +00:00
|
|
|
register: dhcpd_register_nameservers
|
|
|
|
changed_when: False
|
|
|
|
when: dhcpd_mode == 'server'
|
2016-04-08 10:03:33 +00:00
|
|
|
always_run: yes
|
2015-03-29 20:56:46 +00:00
|
|
|
|
|
|
|
- name: Convert list of nameservers to Ansible list
|
|
|
|
set_fact:
|
2015-08-29 18:01:23 +00:00
|
|
|
dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}"
|
2015-03-29 20:56:46 +00:00
|
|
|
when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout)
|
|
|
|
|
2014-08-26 21:36:08 +00:00
|
|
|
- name: Configure DHCP server
|
2015-03-27 09:50:21 +00:00
|
|
|
template:
|
|
|
|
src: '{{ item }}.j2'
|
|
|
|
dest: '/{{ item }}'
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
2014-08-26 21:36:08 +00:00
|
|
|
with_items: [ 'etc/default/isc-dhcp-server', 'etc/dhcp/dhcpd.conf' ]
|
2015-03-27 09:50:21 +00:00
|
|
|
notify: [ 'Restart isc-dhcp-server' ]
|
2015-04-07 11:03:48 +00:00
|
|
|
register: dhcpd_register_config
|
2015-03-27 13:32:44 +00:00
|
|
|
when: dhcpd_mode == 'server'
|
2014-08-26 21:36:08 +00:00
|
|
|
|
2015-04-07 11:03:48 +00:00
|
|
|
- name: Make sure that included files exist
|
|
|
|
file:
|
|
|
|
path: '{{ item }}'
|
|
|
|
state: 'touch'
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
2016-04-13 07:23:26 +00:00
|
|
|
with_items: '{{ dhcpd_includes }}'
|
2015-04-07 11:03:48 +00:00
|
|
|
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))
|
|
|
|
|
2015-03-29 19:13:24 +00:00
|
|
|
- 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'
|
|
|
|
|
2015-03-30 11:34:53 +00:00
|
|
|
- include: dhcp-probe.yml
|
|
|
|
when: dhcpd_probe|d() and dhcpd_probe
|
|
|
|
|