Add hosts to expected ansible groups

Openshift-ansible expects that on initial deployment the nodes belong
to a <host_type> group, while on scale up, it expects the new nodes to
belong to a new_<host_type> group and not be part of the <host_type>
one.

Change-Id: Ibe461b4a7948813b69a0f85642e01aebb0531043
This commit is contained in:
Martin André 2018-11-12 12:48:19 +01:00
parent d295cd94b8
commit cca4eb3aeb
2 changed files with 28 additions and 29 deletions

View File

@ -203,8 +203,8 @@ outputs:
openshift_master_cluster_hostname: {get_param: [EndpointMap, OpenshiftPublic, host]}
openshift_master_cluster_public_hostname: {get_param: [EndpointMap, OpenshiftPublic, host]}
# NOTE(flaper87): Check if origin-node is running in the openshift
# nodes so we can flag the node as new later on.
# 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
@ -212,27 +212,26 @@ outputs:
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: "{{node_services.results | selectattr('item', 'equalto', item) | selectattr('rc', 'greaterthan', 0) | list | count > 0}}"
- 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 | list}}"
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}}"
# NOTE(flaper87): Every master node will be in the masters group
# but only new master nodes will be in the new_masters section, which
# will be created only if there are nodes to add. We'll add `new_masters`
# to the OSEv3 group regardless to simplify the implementation. Ansible
# will ignore the section if it doesn't exist or if it's empty
- name: generate openshift inventory for openshift_master service
copy:
dest: "{{playbook_dir}}/openshift/inventory/{{tripleo_role_name}}_openshift_master.yml"
content: |
{% if master_nodes | count > 0%}
{% if (master_nodes + new_master_nodes) | count > 0%}
all:
children:
masters:
@ -247,18 +246,13 @@ outputs:
{% if new_master_nodes | count > 0 -%}
new_masters:
hosts:
# FIXME(mandre)
# patterns do not work in inventory files, so we
# can't write something like
# hosts:
# new_nodes:&masters: {}
#
# Also impossible to register var with templated
# name, we can't re-use the all_role_nodes var
# for the master role in openshift-node.yaml
{% for host in new_master_nodes -%}
{{host.hostname}}:
{% endfor %}
vars:
{{openshift_master_node_vars | to_nice_yaml() | indent(6)}}
{% endif %}
{% endif %}

View File

@ -81,6 +81,7 @@ outputs:
- name: set role facts for generating inventory
set_fact:
tripleo_role_name: {get_param: RoleName}
tripleo_stack_action: {get_param: StackAction}
tripleo_node_group_name: {get_attr: [RoleParametersValue, value, OpenShiftNodeGroupName]}
openshift_master_network: {get_param: [ServiceNetMap, OpenshiftMasterNetwork]}
tripleo_openshift_deployment_type: {get_param: OpenShiftDeploymentType}
@ -93,8 +94,8 @@ outputs:
atomic-openshift
{%- endif -%}
# NOTE(flaper87): Check if origin-node is running in the openshift
# nodes so we can flag the node as new later on.
# 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
@ -102,14 +103,15 @@ outputs:
with_items: "{{ groups[tripleo_role_name] | default([]) }}"
failed_when: false
# NOTE(flaper87): Create all the nodes objects
# now, as yaml dicts, instead of formatting
# everything as part of a template.
# We consider new_node all the nodes that
# exited with 1 in the previous task.
# NOTE(flaper87): Create all the nodes objects now, as yaml dicts,
# instead of formatting everything as part of a template.
# 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: "{{node_services.results | selectattr('item', 'equalto', item) | selectattr('rc', 'greaterthan', 0) | list | count > 0}}"
- new_node: "{{ tripleo_stack_action == 'UPDATE' and node_services.results | selectattr('item', 'equalto', item) | selectattr('rc', 'greaterthan', 0) | list | count > 0 }}"
hostname: "{{item}}"
ansible_user: "{{ hostvars[item]['ansible_user'] | default(hostvars[item]['ansible_ssh_user']) | default('root') }}"
ansible_host: "{{ hostvars[item]['ansible_host'] | default(item) }}"
@ -124,7 +126,7 @@ outputs:
with_items: "{{groups[tripleo_role_name] | default([]) }}"
- set_fact:
role_nodes: "{{all_role_nodes.results | map(attribute='ansible_facts') | map(attribute='nodes') | flatten | list}}"
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}}"
- set_fact:
@ -137,18 +139,21 @@ outputs:
{% if role_nodes | count > 0%}
all:
hosts:
{% for host in role_nodes -%}
{% for host in (role_nodes + new_role_nodes) -%}
{{host.hostname}}:
{{host | to_nice_yaml() | indent(6)}}
{% endfor %}
children:
{% if role_nodes | count > 0 -%}
nodes:
hosts:
{% for host in role_nodes -%}
{{host.hostname}}:
{% endfor %}
{% endif %}
{% if new_role_nodes | count > 0 -%}
new_nodes:
hosts: