kayobe/ansible/compute-node-provide.yml
Mark Goddard 697b2eecc2 Create a baremetal-compute group for baremetal compute nodes
The compute group was used in a few places, but this now overlaps with
the group used for virtualised compute nodes.
2017-11-12 09:35:40 +00:00

81 lines
2.9 KiB
YAML

---
# This playbook will ensure that all baremetal compute nodes in the overcloud
# ironic inventory are available. Supported initial states include 'enroll' and
# 'manageable'.
- name: Ensure baremetal compute nodes are available in ironic
hosts: controllers[0]
vars:
venv: "{{ virtualenv_path }}/shade"
# Set this to a colon-separated list of baremetal compute node hostnames to
# provide. If unset, all baremetal compute nodes will be provided.
compute_node_limit: ""
compute_node_limit_list: "{{ compute_node_limit.split(':') }}"
roles:
- role: stackhpc.os-openstackclient
os_openstackclient_venv: "{{ venv }}"
tasks:
- name: Get a list of ironic nodes
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node list --fields name provision_state -f json --no-maintenance
register: ironic_node_list
changed_when: False
environment: "{{ openstack_auth_env }}"
- name: Initialise a fact containing the ironic nodes
set_fact:
ironic_nodes: []
- name: Update a fact containing the ironic nodes
set_fact:
ironic_nodes: "{{ ironic_nodes + [item] }}"
with_items: "{{ ironic_node_list.stdout | from_json }}"
when: >
{{ not compute_node_limit or
item['Name'] in compute_node_limit_list }}
- name: Ensure ironic nodes are managed
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node manage {{ item['Name'] }}
with_items: "{{ ironic_nodes }}"
when: item['Provisioning State'] == 'enroll'
environment: "{{ openstack_auth_env }}"
- name: Ensure ironic nodes are available
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node provide {{ item['Name'] }}
with_items: "{{ ironic_nodes }}"
when: item['Provisioning State'] in ['enroll', 'manageable']
environment: "{{ openstack_auth_env }}"
- name: Get a list of ironic nodes
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node list -f json -c Name -c 'Provisioning State' --no-maintenance
register: ironic_node_list
changed_when: False
environment: "{{ openstack_auth_env }}"
- name: Initialise a fact containing the ironic nodes
set_fact:
ironic_nodes: []
- name: Limit ironic nodes to the specified list
set_fact:
ironic_nodes: "{{ ironic_nodes + [item] }}"
with_items: "{{ ironic_node_list.stdout | from_json }}"
when: >
{{ not compute_node_limit or
item['Name'] in compute_node_limit_list }}
- name: Fail if any ironic nodes are not available
fail:
msg: >
Failed to make baremetal compute node {{ item['Name'] }} available in ironic.
Provisioning state is {{ item['Provisioning State'] }}.
with_items: "{{ ironic_nodes }}"
when: item['Provisioning State'] != 'available'