From: David Galloway Date: Fri, 17 Jul 2020 16:57:37 +0000 (-0400) Subject: dhcp-server: Support for `option host-name` declaration X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e57f203e3282771a13da3ea360b2fd90599bd32f;p=ceph-cm-ansible.git dhcp-server: Support for `option host-name` declaration Signed-off-by: David Galloway --- diff --git a/roles/dhcp-server/README.rst b/roles/dhcp-server/README.rst index 6cd3fc8..a3f6762 100644 --- a/roles/dhcp-server/README.rst +++ b/roles/dhcp-server/README.rst @@ -94,6 +94,8 @@ This role basically has two required and two optional variables: | - 5.6.7.8 | | | | | +---------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``dhcp_option_hostname: False`` | Should this host get ``option host-name "{{ ansible_host }}";`` defined in its host declaration? Defaults to False. Override in secrets repo per host/group. | ++---------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. _docs: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable .. _dhcpd: https://linux.die.net/man/8/dhcpd diff --git a/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 b/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 index 331eca0..2d93039 100644 --- a/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 +++ b/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 @@ -66,6 +66,9 @@ subnet {{ subnet_item.cidr | ipaddr('network') }} netmask {{ subnet_item.cidr | {% endif -%} hardware ethernet {{ hostvars[host][subnet_item.macvar] }}; fixed-address {{ hostvars[host][subnet_item.ipvar] }}; + {% if hostvars[host]['dhcp_option_hostname'] is defined and hostvars[host]['dhcp_option_hostname'] == true %} + option host-name "{{ host.split('.')[0] }}"; + {% endif -%} } {% endif -%} {% endif -%}