tripleo-validations/roles/check_uc_hostname/tasks/main.yml

71 lines
2.6 KiB
YAML

---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Make sure stack plan is in the inventory
fail:
msg: |
Stack plan not found
Check your ansible inventory to make sure your plan attribute is defined
when: hostvars[ check_uc_hostname_inventory_host ].plan is not defined
- name: Get stack plan from inventory
set_fact:
plan: "{{ hostvars[ check_uc_hostname_inventory_host ].plan }}"
- name: Retrieve stack environment
command: "openstack stack environment show -f yaml {{ plan }}"
register: stack_env
- name: Fail if we can't find DockerInsecureRegistryAddress
fail:
msg: |
DockerInsecureRegistryAddress not defined
when: stack_env.stdout.find("DockerInsecureRegistryAddress") == -1
- when:
- stack_env.stdout.find("DockerInsecureRegistryAddress") != -1
block:
- name: Query stack for DockerInsecureRegistryAddress
become: true
hiera:
name: container_image_prepare_node_names
- name: Get DockerInsecureRegistryAddress value from stack's environment
set_fact:
uc_hostname_parameter_defaults: "{{ dict(stack_env.get('stdout', default_stdout)
| from_yaml).parameter_defaults.DockerInsecureRegistryAddress
| regex_replace(':\\w+', '') }}"
- name: Get UC hostname (DockerInsecureRegistryAddress) from hiera
set_fact:
uc_hostname_stack: "{{ ansible_facts.container_image_prepare_node_names }}"
- name: Get Intersect between UC hostname from stack and parameter_defaults
set_fact:
intersect: "{{ uc_hostname_stack | intersect(uc_hostname_parameter_defaults) }}"
- name: An Intersect match means parameter_defaults was updated by customer correctly
set_fact:
mismatch: "{{ uc_hostname_stack | difference(intersect) }}"
- name: Verify UC hostnames match
fail:
msg: |
The UC hostnames from stack and containers-prepare-parameter.yaml must match
UC hostname from parameter_defaults is {{ uc_hostname_parameter_defaults }}
UC hostname from stack (hiera) is {{ uc_hostname_stack }}
failed_when: mismatch != []