Store nodes information in a dict
Re-using the same variable for each role was not very clean and forced us to re-check which master nodes were new in the deployment. Instead, use a dict for `role_nodes` and `new_role_nodes` with keys being the role name. This will allow us to re-generate updated inventory in later step without needing to set the facts once again. Related-Bug: #1812962 Change-Id: I21ed56a1c4d43a3e0945c8b74dd94ccf89dc05b0
This commit is contained in:
parent
cb675a91a7
commit
1febc8b7b3
@ -297,50 +297,26 @@ outputs:
|
||||
openshift_master_cluster_hostname: {get_param: [EndpointMap, OpenshiftInternal, host]}
|
||||
openshift_master_cluster_public_hostname: {get_param: [EndpointMap, OpenshiftPublic, host]}
|
||||
|
||||
# NOTE(flaper87): Check if the node service is running in the
|
||||
# openshift nodes so we can flag the node as new later on.
|
||||
- name: Check if node service is running
|
||||
command: "systemctl is-active --quiet {{tripleo_openshift_service_type}}-node"
|
||||
register: node_services
|
||||
delegate_to: "{{item}}"
|
||||
with_items: "{{ groups[tripleo_role_name] | default([]) }}"
|
||||
failed_when: false
|
||||
|
||||
# We consider new_node all the nodes that exited with a non-zero
|
||||
# status in the previous task *IF* this is a stack update.
|
||||
# Openshift-ansible expects nodes to be in the new_nodes group for
|
||||
# scale up operation only.
|
||||
- set_fact:
|
||||
nodes:
|
||||
- new_node: "{{tripleo_stack_action == 'UPDATE' and node_services.results | selectattr('item', 'equalto', item) | selectattr('rc', 'greaterthan', 0) | list | count > 0}}"
|
||||
hostname: "{{item}}"
|
||||
register: all_master_nodes
|
||||
with_items: "{{groups[tripleo_role_name] | default([]) }}"
|
||||
|
||||
- set_fact:
|
||||
master_nodes: "{{all_master_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', False) | list}}"
|
||||
new_master_nodes: "{{all_master_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', True) | list}}"
|
||||
|
||||
- name: generate openshift inventory for openshift_master service
|
||||
copy:
|
||||
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_openshift_master.yml"
|
||||
content: |
|
||||
{% if (master_nodes + new_master_nodes) | count > 0%}
|
||||
{% if (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) | count > 0%}
|
||||
all:
|
||||
children:
|
||||
masters:
|
||||
hosts:
|
||||
{% for host in master_nodes -%}
|
||||
{% for host in role_nodes[tripleo_role_name] -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
vars:
|
||||
{{openshift_master_node_vars | to_nice_yaml() | indent(6)}}
|
||||
|
||||
{% if new_master_nodes | count > 0 -%}
|
||||
{% if new_role_nodes[tripleo_role_name] | count > 0 -%}
|
||||
new_masters:
|
||||
hosts:
|
||||
{% for host in new_master_nodes -%}
|
||||
{% for host in new_role_nodes[tripleo_role_name] -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
@ -453,7 +429,7 @@ outputs:
|
||||
service:
|
||||
name: dnsmasq
|
||||
state: restarted
|
||||
{% if new_master_nodes | count > 0 %}
|
||||
{% if new_role_nodes[tripleo_role_name] | count > 0 %}
|
||||
# Scale up nodes (including masters)
|
||||
- import_playbook: "{{openshift_master_scaleup_playbook_path}}"
|
||||
{% else %}
|
||||
@ -498,29 +474,29 @@ outputs:
|
||||
# view of osa and need to be moved from new_masters and
|
||||
# new_nodes group to masters and nodes groups respectively. In
|
||||
# addition they need to be added to new_etcd groups.
|
||||
- when: tripleo_stack_action == 'UPDATE' and new_master_nodes | count > 0
|
||||
- when: tripleo_stack_action == 'UPDATE' and new_role_nodes[tripleo_role_name] | count > 0
|
||||
block:
|
||||
|
||||
- name: generate updated openshift inventory for openshift_master service
|
||||
copy:
|
||||
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_openshift_master.yml"
|
||||
content: |
|
||||
{% if (master_nodes + new_master_nodes) | count > 0%}
|
||||
{% if (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) | count > 0%}
|
||||
all:
|
||||
children:
|
||||
masters:
|
||||
hosts:
|
||||
{% for host in (master_nodes + new_master_nodes) -%}
|
||||
{% for host in (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
vars:
|
||||
{{openshift_master_node_vars | to_nice_yaml() | indent(6)}}
|
||||
|
||||
{% if new_master_nodes | count > 0 -%}
|
||||
{% if new_role_nodes[tripleo_role_name] | count > 0 -%}
|
||||
new_etcd:
|
||||
hosts:
|
||||
{% for host in new_master_nodes -%}
|
||||
{% for host in new_role_nodes[tripleo_role_name] -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
@ -534,12 +510,12 @@ outputs:
|
||||
copy:
|
||||
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_groups.yml"
|
||||
content: |
|
||||
{% if (master_nodes + new_master_nodes) | count > 0%}
|
||||
{% if (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) | count > 0%}
|
||||
all:
|
||||
children:
|
||||
nodes:
|
||||
hosts:
|
||||
{% for host in (master_nodes + new_master_nodes) -%}
|
||||
{% for host in (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
|
@ -126,20 +126,20 @@ outputs:
|
||||
with_items: "{{groups[tripleo_role_name] | default([]) }}"
|
||||
|
||||
- set_fact:
|
||||
role_nodes: "{{all_role_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', False) | list}}"
|
||||
new_role_nodes: "{{all_role_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', True) | list}}"
|
||||
role_nodes: "{{ role_nodes|default({}) | combine( {tripleo_role_name: all_role_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', False) | list}) }}"
|
||||
new_role_nodes: "{{ new_role_nodes|default({}) | combine( {tripleo_role_name: all_role_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | selectattr('new_node', 'equalto', True) | list}) }}"
|
||||
|
||||
- set_fact:
|
||||
has_new_nodes: "{{ (has_new_nodes | default(False)) or new_role_nodes | count > 0 }}"
|
||||
has_new_nodes: "{{ (has_new_nodes | default(False)) or new_role_nodes[tripleo_role_name] | count > 0 }}"
|
||||
|
||||
- name: generate openshift inventory for {{tripleo_role_name}} role hosts
|
||||
copy:
|
||||
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_hosts.yml"
|
||||
content: |
|
||||
{% if role_nodes | count > 0%}
|
||||
{% if role_nodes[tripleo_role_name] | count > 0%}
|
||||
all:
|
||||
hosts:
|
||||
{% for host in (role_nodes + new_role_nodes) -%}
|
||||
{% for host in (role_nodes[tripleo_role_name] + new_role_nodes[tripleo_role_name]) -%}
|
||||
{{host.hostname}}:
|
||||
{{host | to_nice_yaml() | indent(6)}}
|
||||
{% endfor %}
|
||||
@ -150,22 +150,22 @@ outputs:
|
||||
copy:
|
||||
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_groups.yml"
|
||||
content: |
|
||||
{% if role_nodes | count > 0%}
|
||||
{% if role_nodes[tripleo_role_name] | count > 0%}
|
||||
all:
|
||||
children:
|
||||
{% if role_nodes | count > 0 -%}
|
||||
{% if role_nodes[tripleo_role_name] | count > 0 -%}
|
||||
nodes:
|
||||
hosts:
|
||||
{% for host in role_nodes -%}
|
||||
{% for host in role_nodes[tripleo_role_name] -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if new_role_nodes | count > 0 -%}
|
||||
{% if new_role_nodes[tripleo_role_name] | count > 0 -%}
|
||||
new_nodes:
|
||||
hosts:
|
||||
{% for host in new_role_nodes -%}
|
||||
{% for host in new_role_nodes[tripleo_role_name] -%}
|
||||
{{host.hostname}}:
|
||||
{% endfor %}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user