Choose first node as bootstrap node name/ip

Previously when Heat was choosing the bootstrap node, it always chose
the first node due to the ResourceGroup ordering.

When it was switched to ansible, the last node was chosen instead due to
unpredictable dict sorting from the inventory.

This patch restores the previous behavior and makes sure the first node
in a group is chosen as the bootstrap node for the both the name
and ip if the sorted_bootstrap_node variable is set.

The variable is used so that the tripleo-heat-templates patch and this
patch can merge, otherwise they'd block each other from merging.

See I6b93f5b0747c5a11d24615a3bbb5516f9be81401 for the
tripleo-heat-templates patch.

Change-Id: I3d595ea5b84f940a3b2dbc69798f69fe03529c10
This commit is contained in:
James Slagle 2019-08-23 09:44:47 -04:00
parent 7137cae523
commit eb5bfcf187
3 changed files with 23 additions and 4 deletions

View File

@ -195,6 +195,7 @@ provisioner:
zaqar_api_network: ctlplane
stack_action: CREATE
stack_update_type: ''
tripleo_role_name: Standalone
validate_controllers_icmp: true
validate_fqdn: false
validate_gateways_icmp: true

View File

@ -15,12 +15,26 @@
{# <service>_short_node_names: <list of hostnames> #}
{% set _ = all_nodes.__setitem__((service ~ '_short_node_names'), (groups[service] | default ([]) | map('extract', hostvars, 'inventory_hostname') | list) + all_nodes_extra_map_data[service ~ '_short_node_names'] | default([])) %}
{# <service>_short_bootstrap_node_name: hostname #}
{% set services = (groups[service] | default ([]) | map('extract', hostvars, 'inventory_hostname')) | list + [all_nodes_extra_map_data[service ~ '_short_bootstrap_node_name'] | default('')] %}
{% set services = (groups[service] | default ([]) | list ) %}
{% if all_nodes_extra_map_data[service ~ '_short_bootstrap_node_name'] is defined %}
{% set services = services + all_nodes_extra_map_data[service ~ '_short_bootstrap_node_name'] %}
{% endif %}
{% if (services | length) > 0 %}
{% set _ = all_nodes.__setitem__((service ~ '_short_bootstrap_node_name'), (services | first)) %}
{% if sorted_bootstrap_node | default(false) %}
{% set _ = all_nodes.__setitem__((service ~ '_short_bootstrap_node_name'), (services | sort | first)) %}
{% else %}
{% set _ = all_nodes.__setitem__((service ~ '_short_bootstrap_node_name'), (services | first)) %}
{% endif %}
{% endif %}
{# <service>_bootstrap_node_ip: hostname #}
{% set services = (groups[service] | default ([]) | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_ip')) | list + [all_nodes_extra_map_data[service ~ '_short_bootstrap_node_ip'] | default('')] %}
{% if sorted_bootstrap_node | default(false) %}
{% set services = (groups[service] | default ([]) | sort | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_ip')) | list %}
{% else %}
{% set services = (groups[service] | default ([]) | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_ip')) | list %}
{% endif %}
{% if all_nodes_extra_map_data[service ~ '_short_bootstrap_node_ip'] is defined %}
{% set services = services + [all_nodes_extra_map_data[service ~ '_short_bootstrap_node_ip']] %}
{% endif %}
{% if (services | length) > 0 %}
{% set _ = all_nodes.__setitem__((service ~ '_bootstrap_node_ip'), (services | first)) %}
{% endif %}

View File

@ -1,4 +1,8 @@
{% set boostrap_node = {} %}
{% set _ = boostrap_node.__setitem__('boostrap_node_id', bootstrap_nodeid) %}
{% if sorted_bootstrap_node | default(false) %}
{% set _ = boostrap_node.__setitem__('boostrap_node_id', groups[tripleo_role_name] | sort | first) %}
{% else %}
{% set _ = boostrap_node.__setitem__('boostrap_node_id', groups[tripleo_role_name] | first) %}
{% endif %}
{# RENDER #}
{{ boostrap_node | to_nice_json }}