Add all_nodes template to tripleo-hieradata.

Add a template for the all_nodes hieradata to tripleo-hieradata.

The network hostnames are also added to the inventory as these vars are
needed by the template. The network IP's are already present in the
inventory. These variables will be used by various tasks that render
hiera data dynamically based on the Ansible inventory only.

Change-Id: I6e1e1c28dc09c9e04119db910068d62409a5afc8
This commit is contained in:
James Slagle 2019-06-13 11:07:55 -04:00
parent c94ee2bbfe
commit 008af910e7
4 changed files with 68 additions and 5 deletions

View File

@ -6,3 +6,4 @@ hieradata_variable_end_string: "{{ '}}' }}"
hieradata_per_host: false
hieradata_templates_list:
- bootstrap_node
- all_nodes

View File

@ -0,0 +1,51 @@
{
"enabled_services": {{ enabled_services | unique | to_nice_json }},
{% for service in enabled_services %}
{# <service>_enabled: true #}
{{ '"' ~ service ~ '_enabled": true,' }}
{# <service>_node_ips: <list of ips> #}
{{ '"' ~ service ~ '_node_ips": ' ~ (groups[service] | default ([]) | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_ip') | list | to_json) ~ ',' }}
{# <service>_node_names: <list of hostnames> #}
{{ '"' ~ service ~ '_node_names": ' ~ (groups[service] | default ([]) | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_hostname') | list | to_json) ~ ',' }}
{# <service>_short_node_names: <list of hostnames> #}
{{ '"' ~ service ~ '_short_node_names": ' ~ (groups[service] | default ([]) | map('extract', hostvars, 'inventory_hostname') | list | to_json) ~ ',' }}
{# <service>_short_bootstrap_node_name: hostname #}
{% set services = (groups[service] | default ([]) | map('extract', hostvars, 'inventory_hostname')) | list %}
{% if (services | length) > 0 %}
{{ '"' ~ service ~ '_short_bootstrap_node_name": ' ~ (services | first | to_json) ~ ',' }}
{% endif %}
{# <service>_bootstrap_node_ip: hostname #}
{% set services = (groups[service] | default ([]) | map('extract', hostvars, service_net_map[service ~ '_network'] | default('ctlplane') ~ '_ip')) | list %}
{% if (services | length) > 0 %}
{{ '"' ~ service ~ '_short_bootstrap_node_ip": ' ~ (services | first | to_json) ~ ',' }}
{% endif %}
{% endfor %}
{# <service>_network: <network> #}
{% for service, network in service_net_map.iteritems() %}
{{ '"' ~ service ~ '": "' ~ network ~ '",' }}
{% endfor %}
{{ '"deploy_identifier": "' ~ deploy_identifier ~ '"' }},
{{ '"stack_action": "' ~ stack_action ~ '"' }},
{{ '"stack_update_type": "' ~ stack_update_type ~ '"' }},
{{ '"container_cli": "' ~ container_cli ~ '"' }},
{{ '"controller_node_ips": "' ~ groups[primary_role_name] | default([]) | map('extract', hostvars, 'ctlplane_ip') | list | join(',') ~ '"' }},
{{ '"controller_node_names": "' ~ groups[primary_role_name] | default([]) | map('extract', hostvars, 'inventory_hostname') | list | join(',') ~ '"' }}
}

View File

@ -240,6 +240,12 @@ class TripleoInventory(object):
hosts[name].update({
"%s_ip" % net:
role_net_ip_map[role][net][idx]})
# Add variables for hostname on each network
for net in role_net_hostname_map[role]:
hosts[name].update({
"%s_hostname" % net:
role_net_hostname_map[role][net][idx]})
networks.update(hosts[name]['enabled_networks'])
children.append(role)

View File

@ -340,7 +340,8 @@ class TestInventory(base.TestCase):
'ansible_host': 'y.y.y.1',
'ctlplane_ip': 'y.y.y.1',
'deploy_server_id': 'd',
'enabled_networks': ['ctlplane']}},
'enabled_networks': ['ctlplane'],
'ctlplane_hostname': 'cp-0.ctlplane.localdomain'}},
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'serial': 1,
@ -351,17 +352,20 @@ class TestInventory(base.TestCase):
'ansible_host': 'x.x.x.1',
'ctlplane_ip': 'x.x.x.1',
'deploy_server_id': 'a',
'enabled_networks': ['ctlplane']},
'enabled_networks': ['ctlplane'],
'ctlplane_hostname': 'c-0.ctlplane.localdomain'},
'c-1': {
'ansible_host': 'x.x.x.2',
'ctlplane_ip': 'x.x.x.2',
'deploy_server_id': 'b',
'enabled_networks': ['ctlplane']},
'enabled_networks': ['ctlplane'],
'ctlplane_hostname': 'c-1.ctlplane.localdomain'},
'c-2': {
'ansible_host': 'x.x.x.3',
'ctlplane_ip': 'x.x.x.3',
'deploy_server_id': 'c',
'enabled_networks': ['ctlplane']}},
'enabled_networks': ['ctlplane'],
'ctlplane_hostname': 'c-2.ctlplane.localdomain'}},
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'serial': 1,
@ -372,7 +376,8 @@ class TestInventory(base.TestCase):
'ansible_host': 'z.z.z.1',
'ctlplane_ip': 'z.z.z.1',
'deploy_server_id': 'e',
'enabled_networks': ['ctlplane']}},
'enabled_networks': ['ctlplane'],
'ctlplane_hostname': 'cs-0.ctlplane.localdomain'}},
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'serial': 1,