tripleo-ansible/tripleo_ansible/playbooks/cli-baremetal-introspect.yaml
Steve Baker e54faf1e10 Reimplement os_tripleo_baremetal_node_introspection
Triggering introspection via the introspection API is discouraged when
also using the Ironic API, because Ironic will be out of sync with
introspection state. This is suspected to be causing occasional errors
in CI and with end users.

This module was one of the very first to be converted from mistral, so
hasn't benefited from the concurrency and logging patterns in later
modules.

The internal implementation of this module has been rewritten, and now
does the following:

- Concurrency uses a ThreadPoolExecutor instead of a custom pool with
  async calls
- Waiting for state changes uses existing openstacksdk wait functions
- Logging ends up in a 'logging' result value instead of calling
  module.log which ansible does not pass back to the caller
- Introspection is triggered by setting the node provision state to
  'inspect'
- Node is powered off after a successful introspection
- Auth configuration relies on environment, as for other modules
- Debug tasks are added to the playbook to print the logging

This was reverted previously due to a 50% failure rate in the periodic
featureset001, the locking interaction between inspector and ironic
has now been fixed so the root cause of these failures is now
resolved.

Change-Id: I24eb7014cc657f50be63767af439208eb854dfb6
Closes-Bug: 1903786
Depends-On: https://review.opendev.org/c/openstack/ironic-inspector/+/803935
2021-08-17 08:37:12 +12:00

122 lines
4.2 KiB
YAML

---
# Copyright 2019 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: Baremetal Introspection for multiple Ironic Nodes
connection: "{{ (tripleo_target_host is defined) | ternary('ssh', 'local') }}"
hosts: "{{ tripleo_target_host | default('localhost') }}"
remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}"
gather_facts: "{{ (tripleo_target_host is defined) | ternary(true, false) }}"
any_errors_fatal: true
vars:
run_validations: false
concurrency: 20
max_retries: 1
node_timeout: 1200
retry_timeout: 120
pre_tasks:
- name: Check for required inputs
fail:
msg: >
Input missing `{{ item }}`
when:
- hostvars[inventory_hostname][item] is undefined
loop:
- node_uuids
tasks:
- name: Set node_uuids_intro fact
set_fact:
node_uuids_intro: "{{ node_uuids }}"
- name: exit if nothing to do
block:
- name: Notice
fail:
msg: No nodes are manageable at this time.
when:
- node_uuids_intro == []
# NOTE(cloudnull): This limits the concurrency so that we're not adding
# more threads than needed.
- name: Set concurrency fact
set_fact:
runtime_concurrency: "{{
((concurrency | int) > (node_uuids_intro | length)) |
ternary((node_uuids_intro | length), (concurrency | int))
}}"
# Pre-introspection validation
- name: Validations block
when:
- run_validations | bool
block:
- name: Check if validation enabled
set_fact:
validations_enabled: "{{ lookup('hiera', 'tripleo_validations_enabled') }}"
run_once: true
become: true
# Pre-introspection validation
# NOTE(cloudnull): The stackrc file is sourced because validations are not
# 100% compatible with clouds.yaml at this time.
- name: Run Validations
shell: |-
source "{{ ansible_home }}/stackrc"
openstack --os-cloud undercloud tripleo validator run --group "pre-introspection"
when:
- validations_enabled | bool
- name: Fail if validations are disabled
fail:
msg: >-
Run validations were enabled but via hiera information disabled.
Check the configuration and try again.
when:
- not (validations_enabled | bool)
# Introspect nodes
- name: Start baremetal introspection
os_tripleo_baremetal_node_introspection:
node_uuids: "{{ node_uuids_intro }}"
concurrency: "{{ runtime_concurrency }}"
max_retries: "{{ max_retries }}"
node_timeout: "{{ node_timeout }}"
retry_timeout: "{{ retry_timeout }}"
log_level: info
register: baremetal_introspection_result
failed_when: false
- name: Introspection log
debug:
var: baremetal_introspection_result.logging
- name: Node introspection summary
debug:
msg: |-
Passed: [{{ baremetal_introspection_result.passed_nodes | join(', ') }}]
Failed: [{{ baremetal_introspection_result.failed_nodes | join(', ') }}]
{% if baremetal_introspection_result.passed_nodes == [] %}
No nodes passed introspection
{% elif baremetal_introspection_result.failed_nodes == [] %}
All nodes completed introspection successfully!
{% endif %}
- name: Node introspection failed and no results are provided
fail:
msg: >-
Nodes failed introspection
when:
- baremetal_introspection_result.failed_nodes != []