From c0073a56f490f112b3470b9139403a8912b5fb31 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Mon, 23 Jul 2018 09:47:25 -0400 Subject: [PATCH] dhcp-server: Support defining nameservers by host or group var Signed-off-by: David Galloway --- roles/dhcp-server/README.rst | 7 +++++++ roles/dhcp-server/templates/dhcpd.subnet.conf.j2 | 3 +++ 2 files changed, 10 insertions(+) diff --git a/roles/dhcp-server/README.rst b/roles/dhcp-server/README.rst index 251dfbe0..4335502b 100644 --- a/roles/dhcp-server/README.rst +++ b/roles/dhcp-server/README.rst @@ -87,6 +87,13 @@ This role basically has two required and two optional variables: +---------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``dhcp_filename: "/pxelinux.0"`` | Same rules as above. This is the TFTP filename the DHCP server should instruct DHCP clients to download. | +---------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +|:: | This can be set at a ``host_var`` or ``group_var`` level in the Ansible inventory. It will **override** the subnet's ``domain_name_servers`` defined in the ``dhcp_subnets`` dictionary. | +| | | +| domain_name_servers: | | +| - 1.2.3.4 | | +| - 5.6.7.8 | | +| | | ++---------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. _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 89816ffd..f96828c3 100644 --- a/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 +++ b/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 @@ -60,6 +60,9 @@ subnet {{ subnet_item.cidr | ipaddr('network') }} netmask {{ subnet_item.cidr | next-server {{ hostvars[host]['dhcp_next_server'] }}; filename "{{ hostvars[host]['dhcp_filename'] }}"; {% endif -%} + {% if hostvars[host]['domain_name_servers'] is defined -%} + option domain-name-servers {{ hostvars[host]['domain_name_servers']|join(', ') }}; + {% endif -%} hardware ethernet {{ hostvars[host][subnet_item.macvar] }}; fixed-address {{ hostvars[host][subnet_item.ipvar] }}; } -- 2.47.3