From fc7d10a49be62808dfba887e33ddff2befaf41f2 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 18 Dec 2020 19:30:00 +0100 Subject: [PATCH] Make DHCP inventory handling more flexible Configure a hostsdir even when inventory_dhcp is false, so that a deployment can use a mixed approach. Stop creating an unused additional DNS hostsdir by default since we disable DNS by default. While we're here, rename disable_dnsmasq_dns -> ! dnsmasq_enable_dns for consistency. Change-Id: If40f044a86cdde6d653bbfb441de53fb4071e390 --- .../bifrost-ironic-install/defaults/main.yml | 11 ++++++++++- .../bifrost-ironic-install/tasks/bootstrap.yml | 13 +++++++------ .../templates/dnsmasq.conf.j2 | 14 +++++++++----- .../notes/inventory-ddf41d563a320201.yaml | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 releasenotes/notes/inventory-ddf41d563a320201.yaml diff --git a/playbooks/roles/bifrost-ironic-install/defaults/main.yml b/playbooks/roles/bifrost-ironic-install/defaults/main.yml index 248650782..870bbaf30 100644 --- a/playbooks/roles/bifrost-ironic-install/defaults/main.yml +++ b/playbooks/roles/bifrost-ironic-install/defaults/main.yml @@ -124,7 +124,6 @@ ipa_builder_git_url: https://opendev.org/openstack/ironic-python-agent-builder prometheus_exporter_git_url: https://opendev.org/openstack/ironic-prometheus-exporter mysql_username: "root" mysql_password: "" -disable_dnsmasq_dns: True ironic_git_folder: /opt/stack/ironic ironicclient_git_folder: /opt/stack/python-ironicclient openstacksdk_git_folder: /opt/stack/openstacksdk @@ -164,6 +163,16 @@ dhcp_pool_start: 192.168.1.200 dhcp_pool_end: 192.168.1.250 dhcp_lease_time: 12h dhcp_static_mask: 255.255.255.0 + +# Whether to enable DNS in dnsmasq. Will conflict with any other DNS server, +# hence disabled by default. +dnsmasq_enable_dns: "{{ not (dnsmasq_disable_dns | default(True) | bool) }}" +# Directory with static DHCP hosts configuration. +dnsmasq_dhcp_hostsdir: "/etc/dnsmasq.d/bifrost.dhcp-hosts.d" +# Uncomment to set up directory with additional hosts for DNS. Useless without +# dnsmasq_enable_dns set to True. +#dnsmasq_additional_hostsdir: "/etc/dnsmasq.d/bifrost.hosts.d" + # Dnsmasq default route for clients. If not defined, dnsmasq will push to clients # as default route the same IP of the dnsmasq server. # If set to false, it will disable default route creation in clients. diff --git a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml index 73407e1a0..387459099 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml @@ -242,22 +242,23 @@ - name: "Create an ESP image" import_tasks: create_esp.yml -- name: "Setup Inventory Hosts Directory" +- name: "Setup additional DHCP hosts directory" file: - path: "/etc/dnsmasq.d/bifrost.hosts.d" + path: "{{ dnsmasq_additional_hostsdir }}" state: directory owner: "root" group: "root" mode: 0755 - when: inventory_dhcp | bool -- name: "Setup Inventory DHCP Hosts Directory" + when: dnsmasq_additional_hostsdir is defined + +- name: "Setup inventory DHCP hosts directory" file: - path: "/etc/dnsmasq.d/bifrost.dhcp-hosts.d" + path: "{{ dnsmasq_dhcp_hostsdir }}" state: directory owner: "root" group: "root" mode: 0755 - when: inventory_dhcp | bool + - name: "Retrieve interface IP informations" set_fact: itf_infos: "{{ internal_interface }}" diff --git a/playbooks/roles/bifrost-ironic-install/templates/dnsmasq.conf.j2 b/playbooks/roles/bifrost-ironic-install/templates/dnsmasq.conf.j2 index 9959addcb..8cc773a1f 100644 --- a/playbooks/roles/bifrost-ironic-install/templates/dnsmasq.conf.j2 +++ b/playbooks/roles/bifrost-ironic-install/templates/dnsmasq.conf.j2 @@ -7,10 +7,10 @@ # Listen on this specific port instead of the standard DNS port # (53). Setting this to zero completely disables DNS function, # leaving only DHCP and/or TFTP. -{% if disable_dnsmasq_dns | bool == true %} -port=0 -{% else %} +{% if dnsmasq_enable_dns | bool == true %} port=53 +{% else %} +port=0 {% endif %} listen-address={{ internal_ip }} @@ -34,9 +34,13 @@ conf-dir=/etc/dnsmasq.d # or if you want it to read another file, as well as /etc/hosts, use # this. #addn-hosts=/etc/banner_add_hosts +{% if dnsmasq_additional_hostsdir is defined %} +addn-hosts={{ dhcp_additional_hostsdir }} +{% endif %} + +dhcp-hostsdir={{ dnsmasq_dhcp_hostsdir }} + {% if inventory_dhcp | bool == true %} -addn-hosts=/etc/dnsmasq.d/bifrost.hosts.d -dhcp-hostsfile=/etc/dnsmasq.d/bifrost.dhcp-hosts.d dhcp-ignore=tag:!known {% endif %} diff --git a/releasenotes/notes/inventory-ddf41d563a320201.yaml b/releasenotes/notes/inventory-ddf41d563a320201.yaml new file mode 100644 index 000000000..bc895a6f5 --- /dev/null +++ b/releasenotes/notes/inventory-ddf41d563a320201.yaml @@ -0,0 +1,15 @@ +--- +features: + - | + The dynamic DHCP inventory hostsdir is now created and enabled by default, + even when ``inventory_dhcp`` is ``false``. +upgrade: + - | + An additional DNS hosts directory is no longer created by default in + ``/etc/dnsmasq.d/bifrost.hosts.d`` when ``inventory_dhcp`` is ``true``. + Set the new variable ``dnsmasq_additional_hostsdir`` to keep the previous + behavior (you'll need ``dnsmasq_enable_dns=true`` to actually use it). +deprecations: + - | + The parameter ``disable_dnsmasq_dns`` has been deprecated in favor of + the new parameter ``dnsmasq_enable_dns``.