Stop assuming a specific inventory structure
It's not safe to assume the ansible inventory follows a particular structure e.g that overcloud group contains children or role groups contain hosts Instead use jinja filters from tripleo-ansible to flatten the inventory to group->host mapping and list the tripleo role, regardless of the parent/child group relationships. Depends-On: I8a47c945656558a0d3baa67a5547f0d859f8c816 Change-Id: If022a4647aaebc4b212bba188cc959ff2f8f9311
This commit is contained in:
parent
3e64d96ebb
commit
7f837e69bb
|
@ -302,7 +302,7 @@ Run the playbook including this role::
|
|||
License
|
||||
=======
|
||||
|
||||
BSD
|
||||
Apache License 2.0
|
||||
|
||||
==================
|
||||
Author Information
|
||||
|
|
|
@ -5,7 +5,7 @@ retry_files_enabled = False
|
|||
callback_whitelist = profile_tasks
|
||||
|
||||
# Attempt to load custom modules whether it's installed system-wide or from a virtual environment
|
||||
test_plugins = test_plugings:$VIRTUAL_ENV/usr/local/share/tripleo-upgrade/playbooks/test_plugins:playbooks/test_plugins
|
||||
test_plugins = test_plugins:$VIRTUAL_ENV/usr/local/share/tripleo-upgrade/playbooks/test_plugins:playbooks/test_plugins
|
||||
library = library:$VIRTUAL_ENV/usr/local/share/tripleo-upgrade/playbooks/library:playbooks/library
|
||||
roles_path = roles:$VIRTUAL_ENV/usr/local/share/ansible/roles/tripleo-upgrade:$VIRTUAL_ENV/usr/local/share/
|
||||
|
||||
|
|
|
@ -11,14 +11,15 @@
|
|||
src: "{{ working_dir }}//tripleo-ansible-inventory.yaml"
|
||||
register: upgrade_tripleo_inventory
|
||||
|
||||
- name: set fact inventory_yaml
|
||||
- name: set inventory facts
|
||||
set_fact:
|
||||
inventory_yaml: "{{ upgrade_tripleo_inventory.content | b64decode | from_yaml }}"
|
||||
inventory_hostmap: "{{ upgrade_tripleo_inventory.content | b64decode | to_inventory_hostmap }}"
|
||||
inventory_roles: "{{ upgrade_tripleo_inventory.content | b64decode | to_inventory_roles }}"
|
||||
|
||||
- name: store roles and register controller role name
|
||||
set_fact:
|
||||
oc_roles: "{{ oc_roles + inventory_yaml.overcloud.children.keys() | list }}"
|
||||
controller_role_name: "{{ inventory_yaml.overcloud.children.keys() | map('regex_search', '^[A-Za-z0-9]*[Cc]ontroller[A-Za-z0-9]*$') | select('string') | list | last }}"
|
||||
oc_roles: "{{ oc_roles + inventory_roles }}"
|
||||
controller_role_name: "{{ inventory_roles | map('regex_search', '^[A-Za-z0-9]*[Cc]ontroller[A-Za-z0-9]*$') | select('string') | list | last }}"
|
||||
|
||||
- name: store sorted roles with controller first(default)
|
||||
set_fact:
|
||||
|
@ -35,26 +36,26 @@
|
|||
- name: Retrieve the pacemaker bootstrap controller node.
|
||||
shell: "sudo hiera -c /etc/puppet/hiera.yaml pacemaker_short_bootstrap_node_name"
|
||||
become_user: "{{ (overcloud_ssh_user) | ternary(overcloud_ssh_user, 'heat-admin') }}"
|
||||
delegate_to: "{{ inventory_yaml[controller_role_name]['hosts'].keys()|first }}"
|
||||
delegate_to: "{{ inventory_hostmap[controller_role_name]|first }}"
|
||||
register: pcmkr_bootstrap_node_out
|
||||
when: not update_cell|bool
|
||||
|
||||
- name: Create ordered Controller's host set (bootstrap node first)
|
||||
vars:
|
||||
pcmkr_bootstrap_node: "{{ pcmkr_bootstrap_node_out.stdout }}"
|
||||
controllers_from_inventory: "{{ inventory_yaml[controller_role_name]['hosts'].keys() | list }}"
|
||||
controllers_from_inventory: "{{ inventory_hostmap[controller_role_name] | list }}"
|
||||
set_fact:
|
||||
controllers_ordered: "{{ controllers_from_inventory|intersect([pcmkr_bootstrap_node]) + controllers_from_inventory|difference([pcmkr_bootstrap_node]) }}"
|
||||
when: not update_cell|bool
|
||||
|
||||
- name: create hosts per role fact
|
||||
set_fact:
|
||||
oc_roles_hosts: "{{ oc_roles_hosts | combine({ item.key : controllers_ordered if item.key == controller_role_name else inventory_yaml[item.key]['hosts'].keys()|list }) }}"
|
||||
loop: "{{ inventory_yaml.overcloud.children | default({}) | dict2items }}"
|
||||
oc_roles_hosts: "{{ oc_roles_hosts | combine({ item : controllers_ordered if item == controller_role_name else inventory_hostmap[item]|list }) }}"
|
||||
loop: "{{ inventory_roles }}"
|
||||
when: not update_cell | bool
|
||||
|
||||
- name: create hosts per role fact for cells
|
||||
set_fact:
|
||||
oc_roles_hosts: "{{ oc_roles_hosts | combine({ item.key : inventory_yaml[item.key]['hosts'].keys()|list }) }}"
|
||||
loop: "{{ inventory_yaml.overcloud.children | default({}) | dict2items }}"
|
||||
oc_roles_hosts: "{{ oc_roles_hosts | combine({ item : inventory_hostmap[item]|list }) }}"
|
||||
loop: "{{ inventory_roles }}"
|
||||
when: update_cell | bool
|
||||
|
|
Loading…
Reference in New Issue