This commit is contained in:
vincent 2024-01-13 17:08:19 +01:00
parent e2a4b6df99
commit 2caa6edbe9
4 changed files with 49 additions and 84 deletions

View File

@ -21,13 +21,11 @@
#
dhcpd_mode: 'server'
# .. envvar:: dhcpd_ipversion
#
# Internet Protocol version to configure: ``4`` or ``6``
dhcpd_ipversion: '4'
# --------------------------------
# ISC DHCP Relay configuration
# --------------------------------
@ -35,23 +33,22 @@ dhcpd_ipversion: '4'
# .. envvar:: dhcpd_relay_servers
#
# List of DHCP servers which should receive the relayed packets
dhcpd_relay_servers: [ '{{ ansible_default_ipv4.gateway
if (ansible_default_ipv4.gateway|d())
else [] }}' ]
dhcpd_relay_servers: [
'{{ ansible_default_ipv4.gateway
if (ansible_default_ipv4.gateway | d())
else [] }}',
]
# .. envvar:: dhcpd_relay_interfaces
#
# List of network interfaces that dhcrelay should listen on
dhcpd_relay_interfaces: []
# .. envvar:: dhcpd_relay_options
#
# Additional dhcrelay options
dhcpd_relay_options: '{{ "-" + dhcpd_ipversion }}'
# ---------------------------------
# ISC DHCP Server configuration
# ---------------------------------
@ -61,7 +58,6 @@ dhcpd_relay_options: '{{ "-" + dhcpd_ipversion }}'
# dhcpd(8) options
dhcpd_server_options: '{{ "-" + dhcpd_ipversion }}'
# ---------------------------
# DHCP main configuration
# ---------------------------
@ -69,15 +65,13 @@ dhcpd_server_options: '{{ "-" + dhcpd_ipversion }}'
# .. envvar:: dhcpd_authoritative
#
# Is this DHCP server authoritative?
dhcpd_authoritative: False
dhcpd_authoritative: false
# .. envvar:: dhcpd_log_facility
#
# Log facility to use
dhcpd_log_facility: 'local7'
# .. envvar:: dhcpd_interfaces
#
# List of network interfaces to listen on for DHCP requests
@ -85,24 +79,20 @@ dhcpd_log_facility: 'local7'
# automatically
dhcpd_interfaces: []
# .. envvar:: dhcpd_lease_time
#
# Max lease time in hours (default lease time is calculated below)
dhcpd_lease_time: '24'
# .. envvar:: dhcpd_global_default_lease_time
#
# Default lease time for all IP address leases (18 hours)
dhcpd_global_default_lease_time: '{{ (((dhcpd_lease_time|int / 2) + 6) * 60 * 60)|round|int }}'
dhcpd_global_default_lease_time: '{{ (((dhcpd_lease_time | int / 2) + 6) * 60 * 60) | round | int }}'
# .. envvar:: dhcpd_global_max_lease_time
#
# Maximum lease time for all IP addresses (24 hours)
dhcpd_global_max_lease_time: '{{ (dhcpd_lease_time|int * 60 * 60)|round|int }}'
dhcpd_global_max_lease_time: '{{ (dhcpd_lease_time | int * 60 * 60) | round | int }}'
# ---------------------------
# DHCP advertised options
@ -112,21 +102,18 @@ dhcpd_global_max_lease_time: '{{ (dhcpd_lease_time|int * 60 * 60)|round|int }}'
#
# If enabled, ISC DHCP server will be configured with a set of automatically
# detected options. See ``auto_options.j2`` template for more details.
dhcpd_auto_options: True
dhcpd_auto_options: true
# .. envvar:: dhcpd_domain_name
#
# Default host domain to advertise
dhcpd_domain_name: '{{ ansible_domain }}'
# .. envvar:: dhcpd_domain_search
#
# List of additional domains which should be checked when looking for hostnames
dhcpd_domain_search: []
# .. envvar:: dhcpd_nameservers
#
# List of nameservers to advertise by default
@ -134,12 +121,10 @@ dhcpd_domain_search: []
# instead.
dhcpd_nameservers: []
# .. envvar:: dhcpd_options
#
# Custom global options formatted as a text block
dhcpd_options: False
dhcpd_options: false
# ----------------
# iPXE support
@ -148,15 +133,13 @@ dhcpd_options: False
# .. envvar:: dhcpd_ipxe
#
# Add iPXE-specific options to ISC DHCP server configuration.
dhcpd_ipxe: False
dhcpd_ipxe: false
# .. envvar:: dhcpd_ipxe_dhcp_space
#
# Add DHCP options iPXE namespace in ``dhcpd.conf`` required to support
# iPXE-specific DHCP options in the DHCP server configuration.
dhcpd_ipxe_dhcp_space: True
dhcpd_ipxe_dhcp_space: true
# .. envvar:: dhcpd_ipxe_chain_filename
#
@ -164,20 +147,17 @@ dhcpd_ipxe_dhcp_space: True
# iPXE boot loader.
dhcpd_ipxe_chain_filename: 'undionly.kpxe'
# .. envvar:: dhcpd_ipxe_filename
#
# File sent to hosts booted with iPXE, by default load the standard menu file.
dhcpd_ipxe_filename: 'menu.ipxe'
# .. envvar:: dhcpd_ipxe_options
#
# Additional DHCP options in a YAML text block format, added in the iPXE
# section of the configuration.
dhcpd_ipxe_options: ''
# ----------------------------------------
# ISC DHCP Server configuration scopes
# ----------------------------------------
@ -193,40 +173,35 @@ dhcpd_ipxe_options: ''
# :ref:`dhcpd_keys` for more details.
dhcpd_keys: []
# .. envvar:: dhcpd_zones
#
# List of DNS zones to update with Dynamic DNS configuration. See
# :ref:`dhcpd_zones` for more details.
dhcpd_zones: []
# .. envvar:: dhcpd_classes
#
# List of client classes (see dhcpd.conf(5)). More informaction can be found in
# :ref:`dhcpd_classes`.
dhcpd_classes: []
# .. envvar:: dhcpd_groups
#
# List of configuration scopes groped together. See :ref:`dhcpd_groups` for
# more details.
dhcpd_groups: []
# .. envvar:: dhcpd_shared_networks
#
# List of shared networks grouping specified subnets together. See
# :ref:`dhcpd_shared_networks` for more details.
dhcpd_shared_networks: []
# .. envvar:: dhcpd_subnets
#
# List of subnets not in a shared network. See :ref:`dhcpd_subnets` for more
# details.
dhcpd_subnets: [ '{{ dhcpd_subnet_default[dhcpd_ipversion] }}' ]
dhcpd_subnets: ['{{ dhcpd_subnet_default[dhcpd_ipversion] }}']
# Default subnet managed automatically
dhcpd_subnet_default:
@ -235,28 +210,25 @@ dhcpd_subnet_default:
routers: '{{ ansible_default_ipv4.gateway | default("") }}'
comment: 'Generated automatically by Ansible'
'6':
subnet: '{{ ((ansible_default_ipv6.address + "/" + ansible_default_ipv6.prefix)
if ansible_default_ipv6.address|d() else "") }}'
subnet:
'{{ ((ansible_default_ipv6.address + "/" + ansible_default_ipv6.prefix)
if ansible_default_ipv6.address | d() else "") }}'
comment: 'Generated automatically by Ansible'
# .. envvar:: dhcpd_hosts
#
# Global list of hosts in DHCP. See ref:`dhcpd_hosts` for more details.
dhcpd_hosts: []
# List of external files to include. See :ref:`dhcpd_includes` for more
# details.
dhcpd_includes: []
# .. envvar:: dhcpd_failovers
#
# DHCP failover configuration. See :ref:`dhcpd_failovers` for more details.
dhcpd_failovers: []
# -----------------------------
# dhcp-probe configuration
# -----------------------------
@ -264,15 +236,13 @@ dhcpd_failovers: []
# .. envvar:: dhcpd_probe
#
# Enable or disable ``dhcp-probe`` script
dhcpd_probe: False
dhcpd_probe: false
# .. envvar:: dhcpd_probe_mail_to
#
# List of mail recipients which will receive messages about unauthorized DHCP
# servers. Set to ``[]`` to disable.
dhcpd_probe_mail_to: [ 'root@{{ ansible_domain }}' ]
dhcpd_probe_mail_to: ['root@{{ ansible_domain }}']
# .. envvar:: dhcpd_probe_page_to
#
@ -281,27 +251,22 @@ dhcpd_probe_mail_to: [ 'root@{{ ansible_domain }}' ]
# setup a mail-SMS gateway and send the SMS messages that way.
dhcpd_probe_page_to: []
# .. envvar:: dhcpd_probe_mail_timeout
#
# Number of seconds between to wait between sending new mail messages
dhcpd_probe_mail_timeout: '{{ (20 * 60) }}'
# .. envvar:: dhcpd_probe_page_timeout
#
# Number of seconds between to wait between sending new pager messages
dhcpd_probe_page_timeout: '{{ (20 * 60) }}'
# .. envvar:: dhcpd_probe_legal_servers
#
# List of IP addresses of the host which are authorized DHCP servers.
dhcpd_probe_legal_servers: []
# .. envvar:: dhcpd_probe_options
#
# Additional ``dhcp-probe`` options specified as a YAML text block.
dhcpd_probe_options: ''

View File

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

View File

@ -1,7 +1,6 @@
---
- name: Configure DHCP relay in debconf
debconf:
ansible.builtin.debconf:
name: 'isc-dhcp-relay'
question: 'isc-dhcp-relay/{{ item.key }}'
vtype: 'string'
@ -16,16 +15,16 @@
- dhcpd_mode == 'relay'
- name: Install DHCP packages
package:
ansible.builtin.package:
name: '{{ item }}'
state: 'present'
with_flattened:
with_community.general.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' ]
ansible.builtin.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,21 +1,23 @@
---
- include: dist_vars.yml
- include: install.yml
- name: Include dist_vars
ansible.builtin.include_tasks: dist_vars.yml
- name: Include install tasks
ansible.builtin.include_tasks: install.yml
- name: Get list of nameservers configured in /etc/resolv.conf
shell: grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
ansible.builtin.shell: set -o pipefail && grep -E '^nameserver\s' /etc/resolv.conf | awk '{print $2}'
register: dhcpd_register_nameservers
changed_when: False
changed_when: false
when: dhcpd_mode == 'server'
check_mode: False
check_mode: false
- name: Convert list of nameservers to Ansible list
set_fact:
ansible.builtin.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
template:
ansible.builtin.template:
src: "etc/dhcp/dhcpd.conf.j2"
dest: "/{{ item }}"
owner: "root"
@ -27,7 +29,7 @@
when: dhcpd_mode == 'server'
- name: Make sure that included files exist
file:
ansible.builtin.file:
path: "{{ item }}"
state: "touch"
owner: "root"
@ -39,14 +41,15 @@
(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
ansible.builtin.command: touch /var/lib/dhcp/dhcpd6.leases creates=/var/lib/dhcp/dhcpd6.leases
when: dhcpd_ipversion == '6'
- include: dhcp-probe.yml
- name: Include dhcp-probe
ansible.builtin.include_tasks: dhcp-probe.yml
when: dhcpd_probe|d() and dhcpd_probe
- name: enable DHCP4
service:
- name: Enable DHCP4
ansible.builtin.service:
name: dhcpd4
state: started
enabled: yes
enabled: true