Skip to content

Commit

Permalink
Merge branch 'Anthony25-use_package'
Browse files Browse the repository at this point in the history
  • Loading branch information
drybjed committed Sep 21, 2017
2 parents 73902b7 + 761f928 commit 4d003ce
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 48 deletions.
9 changes: 0 additions & 9 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# --------------------------------
Expand Down
23 changes: 14 additions & 9 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ galaxy_info:
- name: Debian
versions:
- all
- name: Archlinux
- name: Alpine
categories:
- networking
- system
Expand Down
20 changes: 20 additions & 0 deletions tasks/dist_vars.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 5 additions & 30 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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}'
Expand All @@ -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'

Expand All @@ -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))

Expand All @@ -69,4 +45,3 @@

- include: dhcp-probe.yml
when: dhcpd_probe|d() and dhcpd_probe

22 changes: 22 additions & 0 deletions vars/Alpine.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions vars/default.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

# vim: set ts=2 sw=2:

0 comments on commit 4d003ce

Please sign in to comment.