From 109cf98c0360348d28f12d7a5f17dd5cbe9ea142 Mon Sep 17 00:00:00 2001 From: Andrey Shestakov Date: Tue, 27 Dec 2016 16:35:49 +0200 Subject: [PATCH] Add dhcp related tasks to inspection role In case when inventory_dhcp is enabled and node is not deployed yet, inspection is not working because dnsmasq ignores requests from unknown address. Change-Id: I048acc5093d186637db2e92915eb019dc3baab91 --- .../bifrost-deploy-nodes-dynamic/README.md | 26 +++++++++--------- playbooks/roles/ironic-inspect-node/README.md | 27 +++++++++++++++++++ .../ironic-inspect-node/defaults/main.yml | 3 +++ .../roles/ironic-inspect-node/tasks/main.yml | 25 +++++++++++++++++ .../templates/dhcp-host.j2 | 6 +++++ .../templates/dns-address.j2 | 2 ++ ...-with-inventory-dhcp-cfc236974bf4ed0a.yaml | 7 +++++ 7 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 playbooks/roles/ironic-inspect-node/templates/dhcp-host.j2 create mode 100644 playbooks/roles/ironic-inspect-node/templates/dns-address.j2 create mode 100644 releasenotes/notes/fix-inspection-with-inventory-dhcp-cfc236974bf4ed0a.yaml diff --git a/playbooks/roles/bifrost-deploy-nodes-dynamic/README.md b/playbooks/roles/bifrost-deploy-nodes-dynamic/README.md index b776e2a9a..7081e8d1a 100644 --- a/playbooks/roles/bifrost-deploy-nodes-dynamic/README.md +++ b/playbooks/roles/bifrost-deploy-nodes-dynamic/README.md @@ -67,16 +67,16 @@ inventory_dhcp: A boolean value, defaulted to false, which allows dnsmasq parameter. inventory_dhcp_static_ip: A boolean value, defaulted to true, which configures - the mechanism for setting up the IP of machines when - inventory_dhcp is enabled. - If set to true, it will read the value of the key - 'provisioning_ipv4_address' from the inventory section - of each machine and dnsmasq will assign that IP to each - machine accordingly. Note, that if you don't assign - the key 'provisioning_ipv4_address' it will default - to the value of 'ipv4_address'. - If set to false, dnsmasq will assign IPs - automatically from the configured DHCP range. + the mechanism for setting up the IP of machines when + inventory_dhcp is enabled. + If set to true, it will read the value of the key + 'provisioning_ipv4_address' from the inventory section + of each machine and dnsmasq will assign that IP to each + machine accordingly. Note, that if you don't assign + the key 'provisioning_ipv4_address' it will default + to the value of 'ipv4_address'. + If set to false, dnsmasq will assign IPs + automatically from the configured DHCP range. noauth_mode: Controls if the module is called in noauth mode. By default, this is the standard mode of operation, @@ -89,9 +89,9 @@ cloud_name: Optional: String value defining a clouds.yaml entry for the ansible module to leverage. inventory_dns: A boolean value, defaulted to false, which causes the role - to update a template file and reload dnsmasq upon each update - in order to perform static dns addressing utilizing the - ipv4_address parameter. + to update a template file and reload dnsmasq upon each update + in order to perform static dns addressing utilizing the + ipv4_address parameter. Dependencies ------------ diff --git a/playbooks/roles/ironic-inspect-node/README.md b/playbooks/roles/ironic-inspect-node/README.md index f33bd66c1..732152bbc 100644 --- a/playbooks/roles/ironic-inspect-node/README.md +++ b/playbooks/roles/ironic-inspect-node/README.md @@ -39,6 +39,33 @@ inspection_wait_timeout: Integer value in seconds, defaults to 1800. under 300 seconds, although that will vary based upon the hardware configuration. +inventory_dhcp: A boolean value, defaulted to false, which allows dnsmasq + to configure the IP of the machines, rather than putting + the IP configuration of the machine in the config drive. + If set to true, the role will create a file for each machine + under /etc/dnsmasq.d/bifrost.dhcp-hosts.d containing the mac, + name of the machine, lease time and optionally the IP address + that will be offered to the machine by DHCP. + This optional IP is controlled by the inventory_dhcp_static_ip + parameter. + +inventory_dhcp_static_ip: A boolean value, defaulted to true, which configures + the mechanism for setting up the IP of machines when + inventory_dhcp is enabled. + If set to true, it will read the value of the key + 'provisioning_ipv4_address' from the inventory section + of each machine and dnsmasq will assign that IP to each + machine accordingly. Note, that if you don't assign + the key 'provisioning_ipv4_address' it will default + to the value of 'ipv4_address'. + If set to false, dnsmasq will assign IPs + automatically from the configured DHCP range. + +inventory_dns: A boolean value, defaulted to false, which causes the role + to update a template file and reload dnsmasq upon each update + in order to perform static dns addressing utilizing the + ipv4_address parameter. + Dependencies ------------ diff --git a/playbooks/roles/ironic-inspect-node/defaults/main.yml b/playbooks/roles/ironic-inspect-node/defaults/main.yml index 88ffdfd0f..436e04e5f 100644 --- a/playbooks/roles/ironic-inspect-node/defaults/main.yml +++ b/playbooks/roles/ironic-inspect-node/defaults/main.yml @@ -2,3 +2,6 @@ # defaults file for ironic-inspect-node noauth_mode: true inspection_wait_timeout: 1800 +inventory_dhcp: false +inventory_dhcp_static_ip: true +inventory_dns: false diff --git a/playbooks/roles/ironic-inspect-node/tasks/main.yml b/playbooks/roles/ironic-inspect-node/tasks/main.yml index e98ee215e..4af870b6a 100644 --- a/playbooks/roles/ironic-inspect-node/tasks/main.yml +++ b/playbooks/roles/ironic-inspect-node/tasks/main.yml @@ -32,6 +32,31 @@ when: auth is undefined no_log: yes +- name: "Setup DHCP for nodes." + template: + src: dhcp-host.j2 + dest: "/etc/dnsmasq.d/bifrost.dhcp-hosts.d/{{ inventory_hostname }}" + owner: root + group: root + mode: 0644 + when: inventory_dhcp | bool == true + become: yes +- name: "Setup DNS address for nodes." + template: + src: dns-address.j2 + dest: "/etc/dnsmasq.d/host_record_{{ inventory_hostname }}" + owner: root + group: root + mode: 0644 + when: inventory_dns | bool == true + become: yes +- name: "Sending dnsmasq HUP" + # Note(TheJulia): We need to actually to send a hup signal directly as + # Ansible's reloaded state does not pass through to the init script. + command: killall -HUP dnsmasq + become: yes + when: (inventory_dhcp | bool == true) or (inventory_dns | bool == true) + - name: "Execute node introspection" os_ironic_inspect: cloud: "{{ cloud_name | default(omit) }}" diff --git a/playbooks/roles/ironic-inspect-node/templates/dhcp-host.j2 b/playbooks/roles/ironic-inspect-node/templates/dhcp-host.j2 new file mode 100644 index 000000000..d9f11f1fb --- /dev/null +++ b/playbooks/roles/ironic-inspect-node/templates/dhcp-host.j2 @@ -0,0 +1,6 @@ +# This file is managed by bifrost +{% if inventory_dhcp_static_ip | bool == true %} +{{ nics[0]['mac'] }},{{provisioning_ipv4_address}},{{name}},12h +{% else %} +{{ nics[0]['mac'] }},{{name}},12h +{% endif %} diff --git a/playbooks/roles/ironic-inspect-node/templates/dns-address.j2 b/playbooks/roles/ironic-inspect-node/templates/dns-address.j2 new file mode 100644 index 000000000..4792c23cd --- /dev/null +++ b/playbooks/roles/ironic-inspect-node/templates/dns-address.j2 @@ -0,0 +1,2 @@ +# This file is managed by bifrost +host-record={{ inventory_hostname }},{{ ipv4_address }} diff --git a/releasenotes/notes/fix-inspection-with-inventory-dhcp-cfc236974bf4ed0a.yaml b/releasenotes/notes/fix-inspection-with-inventory-dhcp-cfc236974bf4ed0a.yaml new file mode 100644 index 000000000..d0c30f28e --- /dev/null +++ b/releasenotes/notes/fix-inspection-with-inventory-dhcp-cfc236974bf4ed0a.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - Added dhcp configuration tasks to inspection role. + In case when inventory_dhcp is enabled and node is not deployed yet, + inspection is not working because dnsmasq ignores requests from unknown + address. This fix introduces tasks which configures dhcp before + inspection.