Merge branch 'Anthony25-use_package'

This commit is contained in:
Maciej Delmanowski 2017-09-21 13:38:58 +02:00
commit 4d003cee65
No known key found for this signature in database
GPG Key ID: 375A77ECA0A04619
12 changed files with 183 additions and 48 deletions

View File

@ -28,15 +28,6 @@ dhcpd_mode: 'server'
dhcpd_ipversion: '4'
# .. envvar:: dhcpd_base_packages_map
#
# What packages should be installed, depending on mode of operation
dhcpd_base_packages_map:
'server': [ 'isc-dhcp-server' ]
'relay': [ 'isc-dhcp-relay' ]
'probe': []
# --------------------------------
# ISC DHCP Relay configuration
# --------------------------------

View File

@ -1,23 +1,28 @@
---
- name: Restart isc-dhcp-server
- name: Restart dhcp server
service:
name: 'isc-dhcp-server'
name: '{{ item }}'
state: 'restarted'
with_items: "{{ dhcpd_services.server }}"
- name: Restart isc-dhcp-relay
- name: Restart dhcp relay
service:
name: 'isc-dhcp-relay'
name: '{{ item }}'
state: 'restarted'
with_items: "{{ dhcpd_services.relay }}"
- name: Restart dhcp-probe
- name: Restart dhcp probe
service:
name: 'dhcp-probe'
name: '{{ item }}'
state: 'stopped'
notify: [ 'Start dhcp-probe' ]
with_items: "{{ dhcpd_services.probe }}"
notify: [ 'Start dhcp probe' ]
- name: Start dhcp-probe
- name: Start dhcp probe
service:
name: 'dhcp-probe'
name: '{{ item }}'
state: 'started'
with_items: "{{ dhcpd_services.probe }}"
# vim: set ts=2 sw=2:

View File

@ -17,6 +17,8 @@ galaxy_info:
- name: Debian
versions:
- all
- name: Archlinux
- name: Alpine
categories:
- networking
- system

20
tasks/dist_vars.yml Normal file
View File

@ -0,0 +1,20 @@
---
- name: Include distribution specific variables
include_vars:
file: "{{ item }}"
name: _os_specific
with_first_found:
- "{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- "default.yml"
- name: Set OS specific vars if undefined
set_fact: {
"{{ item.key }}":
"{{ hostvars[inventory_hostname][item.key] | default(item.value) }}"
}
with_dict: "{{ _os_specific }}"
# vim: set ts=2 sw=2:

31
tasks/install.yml Normal file
View File

@ -0,0 +1,31 @@
---
- 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:
- ansible_os_family == "Debian"
- dhcpd_mode == 'relay'
- name: Install DHCP packages
package:
name: '{{ item }}'
state: 'present'
with_flattened:
- '{{ dhcpd_base_packages_map[dhcpd_mode] }}'
- '{{ dhcpd_base_packages_map["probe"] }}'
- name: Reconfigure ISC DHCP relay
command: dpkg-reconfigure --frontend=noninteractive isc-dhcp-relay
notify: [ 'Restart dhcp relay' ]
when:
- ansible_os_family == "Debian"
- dhcpd_register_relay_debconf|d() and dhcpd_register_relay_debconf.changed

View File

@ -1,31 +1,7 @@
---
- 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'
- 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
- include: dist_vars.yml
- include: install.yml
- name: Get list of nameservers configured in /etc/resolv.conf
shell: grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
@ -46,8 +22,8 @@
owner: 'root'
group: 'root'
mode: '0644'
with_items: [ 'etc/default/isc-dhcp-server', 'etc/dhcp/dhcpd.conf' ]
notify: [ 'Restart isc-dhcp-server' ]
with_items: "{{ dhcpd_templates }}"
notify: [ 'Restart dhcp server' ]
register: dhcpd_register_config
when: dhcpd_mode == 'server'
@ -59,7 +35,7 @@
group: 'root'
mode: '0644'
with_items: '{{ dhcpd_includes }}'
notify: [ 'Restart isc-dhcp-server' ]
notify: [ 'Restart dhcp server' ]
when: ((item is defined and item) and dhcpd_mode == 'server' and
(dhcpd_register_config is defined and dhcpd_register_config.changed))
@ -69,4 +45,3 @@
- include: dhcp-probe.yml
when: dhcpd_probe|d() and dhcpd_probe

22
vars/Alpine.yml Normal file
View File

@ -0,0 +1,22 @@
---
dhcpd_base_packages_map:
'server':
- 'dhcp'
'relay':
- 'dhcp'
'probe':
- 'dhcp-probe'
dhcpd_services:
'server':
- 'dhcpd'
'relay':
- 'dhcpd'
'probe':
- 'dhcp-probe'
dhcpd_templates:
- 'etc/dhcp/dhcpd.conf'
# vim: set ts=2 sw=2:

22
vars/Archlinux.yml Normal file
View File

@ -0,0 +1,22 @@
---
dhcpd_base_packages_map:
'server':
- 'dhcp'
'relay':
- 'dhcp'
'probe': []
dhcpd_services:
'server':
- 'dhcpd4'
- 'dhcpd6'
'relay':
- 'dhcpd4'
- 'dhcpd6'
'probe': []
dhcpd_templates:
- 'etc/dhcp/dhcpd.conf'
# vim: set ts=2 sw=2:

22
vars/Debian.yml Normal file
View File

@ -0,0 +1,22 @@
---
dhcpd_base_packages_map:
'server':
- 'isc-dhcp-server'
'relay':
- 'isc-dhcp-relay'
'probe': []
dhcpd_services:
'server':
- 'isc-dhcp-server'
'relay':
- 'isc-dhcp-relay'
'probe':
- 'dhcp-probe'
dhcpd_templates:
- 'etc/default/isc-dhcp-server'
- 'etc/dhcp/dhcpd.conf'
# vim: set ts=2 sw=2:

20
vars/RedHat.yml Normal file
View File

@ -0,0 +1,20 @@
---
dhcpd_base_packages_map:
'server':
- 'dhcp'
'relay':
- 'dhcp'
'probe': []
dhcpd_services:
'server':
- 'dhcpd'
'relay':
- 'dhcpd'
'probe': []
dhcpd_templates:
- 'etc/dhcp/dhcpd.conf'
# vim: set ts=2 sw=2:

22
vars/default.yml Normal file
View File

@ -0,0 +1,22 @@
---
dhcpd_base_packages_map:
'server':
- 'dhcp'
'relay':
- 'dhcp'
'probe': []
dhcpd_services:
'server':
- 'dhcpd4'
- 'dhcpd6'
'relay':
- 'dhcpd4'
- 'dhcpd6'
'probe': []
dhcpd_templates:
- 'etc/dhcp/dhcpd.conf'
# vim: set ts=2 sw=2:

3
vars/main.yml Normal file
View File

@ -0,0 +1,3 @@
---
# vim: set ts=2 sw=2: