diff --git a/defaults/main.yml b/defaults/main.yml index cc234e7..1b7b892 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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,70 +173,62 @@ 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: - '4': - subnet: '{{ ansible_default_ipv4.network + "/" + ansible_default_ipv4.netmask }}' - 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 "") }}' - comment: 'Generated automatically by Ansible' - + '4': + subnet: '{{ ansible_default_ipv4.network + "/" + ansible_default_ipv4.netmask }}' + 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 "") }}' + 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: '' - diff --git a/tasks/dist_vars.yml b/tasks/dist_vars.yml index cbfc849..c561615 100644 --- a/tasks/dist_vars.yml +++ b/tasks/dist_vars.yml @@ -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: diff --git a/tasks/install.yml b/tasks/install.yml index 03ba462..2078612 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,31 +1,30 @@ --- - - name: Configure DHCP relay in debconf - debconf: + ansible.builtin.debconf: name: 'isc-dhcp-relay' question: 'isc-dhcp-relay/{{ item.key }}' vtype: 'string' value: '{{ item.value }}' with_dict: - servers: '{{ dhcpd_relay_servers | join(" ") }}' + servers: '{{ dhcpd_relay_servers | join(" ") }}' interfaces: '{{ dhcpd_relay_interfaces | join(" ") }}' - options: '{{ dhcpd_relay_options }}' + options: '{{ dhcpd_relay_options }}' register: dhcpd_register_relay_debconf when: - ansible_os_family == "Debian" - 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 diff --git a/tasks/main.yml b/tasks/main.yml index 0e50634..544a4e8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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