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

View File

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

View File

@ -1,31 +1,30 @@
--- ---
- name: Configure DHCP relay in debconf - name: Configure DHCP relay in debconf
debconf: ansible.builtin.debconf:
name: 'isc-dhcp-relay' name: 'isc-dhcp-relay'
question: 'isc-dhcp-relay/{{ item.key }}' question: 'isc-dhcp-relay/{{ item.key }}'
vtype: 'string' vtype: 'string'
value: '{{ item.value }}' value: '{{ item.value }}'
with_dict: with_dict:
servers: '{{ dhcpd_relay_servers | join(" ") }}' servers: '{{ dhcpd_relay_servers | join(" ") }}'
interfaces: '{{ dhcpd_relay_interfaces | join(" ") }}' interfaces: '{{ dhcpd_relay_interfaces | join(" ") }}'
options: '{{ dhcpd_relay_options }}' options: '{{ dhcpd_relay_options }}'
register: dhcpd_register_relay_debconf register: dhcpd_register_relay_debconf
when: when:
- ansible_os_family == "Debian" - ansible_os_family == "Debian"
- dhcpd_mode == 'relay' - dhcpd_mode == 'relay'
- name: Install DHCP packages - name: Install DHCP packages
package: ansible.builtin.package:
name: '{{ item }}' name: '{{ item }}'
state: 'present' state: 'present'
with_flattened: with_community.general.flattened:
- '{{ dhcpd_base_packages_map[dhcpd_mode] }}' - '{{ dhcpd_base_packages_map[dhcpd_mode] }}'
- '{{ dhcpd_base_packages_map["probe"] }}' - '{{ dhcpd_base_packages_map["probe"] }}'
- name: Reconfigure ISC DHCP relay - name: Reconfigure ISC DHCP relay
command: dpkg-reconfigure --frontend=noninteractive isc-dhcp-relay ansible.builtin.command: dpkg-reconfigure --frontend=noninteractive isc-dhcp-relay
notify: [ 'Restart dhcp relay' ] notify: ['Restart dhcp relay']
when: when:
- ansible_os_family == "Debian" - ansible_os_family == "Debian"
- dhcpd_register_relay_debconf|d() and dhcpd_register_relay_debconf.changed - dhcpd_register_relay_debconf|d() and dhcpd_register_relay_debconf.changed

View File

@ -1,21 +1,23 @@
--- ---
- include: dist_vars.yml - name: Include dist_vars
- include: install.yml 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 - 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 register: dhcpd_register_nameservers
changed_when: False changed_when: false
when: dhcpd_mode == 'server' when: dhcpd_mode == 'server'
check_mode: False check_mode: false
- name: Convert list of nameservers to Ansible list - name: Convert list of nameservers to Ansible list
set_fact: ansible.builtin.set_fact:
dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}" dhcpd_runtime_nameservers: "{{ dhcpd_register_nameservers.stdout_lines }}"
when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout) when: (dhcpd_register_nameservers is defined and dhcpd_register_nameservers.stdout)
- name: Configure DHCP server - name: Configure DHCP server
template: ansible.builtin.template:
src: "etc/dhcp/dhcpd.conf.j2" src: "etc/dhcp/dhcpd.conf.j2"
dest: "/{{ item }}" dest: "/{{ item }}"
owner: "root" owner: "root"
@ -27,7 +29,7 @@
when: dhcpd_mode == 'server' when: dhcpd_mode == 'server'
- name: Make sure that included files exist - name: Make sure that included files exist
file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
state: "touch" state: "touch"
owner: "root" owner: "root"
@ -39,14 +41,15 @@
(dhcpd_register_config is defined and dhcpd_register_config.changed)) (dhcpd_register_config is defined and dhcpd_register_config.changed))
- name: Make sure that IPv6 lease file exists - 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' 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 when: dhcpd_probe|d() and dhcpd_probe
- name: enable DHCP4 - name: Enable DHCP4
service: ansible.builtin.service:
name: dhcpd4 name: dhcpd4
state: started state: started
enabled: yes enabled: true