--- # Copyright 2019 Red Hat, Inc. # # 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: TripleO register or update 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: nodes_json: [] remove: false kernel_name: null ramdisk_name: null instance_boot_option: null initial_state: 'manageable' tasks: - name: "Check if temp_file is set" fail: msg: the option temp_file is undefined when: - temp_file is undefined - name: Validate nodes baremetal_nodes_validate: nodes_list: "{{ nodes_json }}" register: result - name: Register or Update nodes baremetal_register_or_update_nodes: nodes_json: "{{ nodes_json }}" remove: "{{ remove }}" kernel_name: "{{ kernel_name }}" ramdisk_name: "{{ ramdisk_name }}" instance_boot_option: "{{ instance_boot_option }}" register: registered_nodes - name: "Registered nodes during enroll" debug: msg: "{{ registered_nodes }}" - name: "Save registered nodes" copy: content: "{{ registered_nodes.nodes | to_json }}" dest: "{{ temp_file }}" - name: Register nodes failed fail: msg: "{{ registered_nodes.error }}" when: result.failed - name: "Exit early if initial state for enroll only" block: - name: "Registered nodes during enroll" debug: msg: "{{ registered_nodes }}" - meta: end_play when: - initial_state == "enroll" - name: "Set new nodes fact" set_fact: new_nodes: "{{ registered_nodes.nodes | selectattr('provision_state', 'eq', 'enroll') | list }}" - name: Make nodes available command: >- openstack --os-cloud undercloud baremetal node manage {{ item.uuid }} --wait 1200 loop: "{{ new_nodes }}" async: 2400 poll: 0 register: node_manageable - name: poll for completion async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ node_manageable.results }}" loop_control: label: "{{ item.item }}" register: wait until: wait.finished retries: 120 - name: "Registered nodes during enroll" debug: msg: "{{ new_nodes | length }} node(s) successfully moved to the 'manageable' state."