Skip to content

Commit f190830

Browse files
committed
ansible directory and playbooks added to
skc-baremetal-environment
1 parent 3eeadec commit f190830

11 files changed

+1018
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
3+
- name: Register baremetal compute nodes
4+
hosts: localhost
5+
vars:
6+
venv: "{{ virtualenv_path }}/openstack-cli"
7+
tasks:
8+
- name: Set up openstack cli virtualenv
9+
pip:
10+
virtualenv: "{{ venv }}"
11+
name:
12+
- python-openstackclient
13+
- python-ironicclient
14+
state: latest
15+
virtualenv_command: "python3.{{ ansible_facts.python.version.minor }} -m venv"
16+
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}"
17+
18+
- name: Ensure overcloud baremetal nodes are registered in ironic
19+
hosts: overcloud
20+
gather_facts: false
21+
max_fail_percentage: >-
22+
{{ baremetal_compute_register_max_fail_percentage |
23+
default(baremetal_compute_max_fail_percentage) |
24+
default(kayobe_max_fail_percentage) |
25+
default(100) }}
26+
tags:
27+
- baremetal
28+
vars:
29+
venv: "{{ virtualenv_path }}/openstack-cli"
30+
controller_host: localhost
31+
tasks:
32+
- name: Check Ironic variables are defined
33+
ansible.builtin.assert:
34+
that:
35+
- ironic_driver is defined
36+
- ironic_driver_info is defined
37+
- ironic_properties is defined
38+
- ironic_resource_class is defined
39+
fail_msg: One or more Ironic variables are undefined.
40+
41+
- block:
42+
- name: Show baremetal node
43+
ansible.builtin.command:
44+
cmd: "{{ venv }}/bin/openstack baremetal node show {{ inventory_hostname }}"
45+
register: node_show
46+
failed_when:
47+
- '"HTTP 404" not in node_show.stderr'
48+
- node_show.rc != 0
49+
changed_when: false
50+
51+
# NOTE: The openstack.cloud.baremetal_node module cannot be used in this
52+
# script due to requiring a MAC address pre-defined, instead, this should
53+
# be discovered by inpsection following this script.
54+
#
55+
# NOTE: IPMI address must be passed with Redfish address to ensure existing
56+
# Ironic nodes match with new nodes during inspection.
57+
- name: Create baremetal nodes
58+
ansible.builtin.shell:
59+
cmd: |
60+
{{ venv }}/bin/openstack baremetal node create \
61+
--name {{ inventory_hostname }} \
62+
--driver {{ ironic_driver }} \
63+
{% for key, value in ironic_driver_info.items() %}
64+
--driver-info {{ key }}={{ value }} \
65+
{% endfor %}
66+
{% for key, value in ironic_properties.items() %}
67+
--property {{ key }}={{ value }} \
68+
{% endfor %}
69+
--resource-class {{ ironic_resource_class }}
70+
when:
71+
- node_show.rc != 0
72+
73+
- name: Manage baremetal nodes
74+
ansible.builtin.command:
75+
cmd: "{{ venv }}/bin/openstack baremetal node manage {{ inventory_hostname }} --wait"
76+
when:
77+
- node_show.rc != 0
78+
delegate_to: "{{ controller_host }}"
79+
vars:
80+
# NOTE: Without this, the controller's ansible_host variable will not
81+
# be respected when using delegate_to.
82+
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
83+
environment: "{{ openstack_auth_env }}"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
- name: Check baremetal compute node bmc is up
3+
hosts: baremetal
4+
gather_facts: false
5+
max_fail_percentage: >-
6+
{{ baremetal_compute_register_max_fail_percentage |
7+
default(baremetal_compute_max_fail_percentage) |
8+
default(kayobe_max_fail_percentage) |
9+
default(100) }}
10+
tags:
11+
- baremetal
12+
vars:
13+
venv: "{{ virtualenv_path }}/openstack-cli"
14+
controller_host: localhost
15+
16+
tasks:
17+
- name: Check Ironic variables are defined
18+
ansible.builtin.assert:
19+
that:
20+
- ironic_driver is defined
21+
- ironic_driver_info is defined
22+
- ironic_properties is defined
23+
- ironic_resource_class is defined
24+
fail_msg: One or more Ironic variables are undefined.
25+
26+
- name: Show and check baremetal node
27+
delegate_to: "{{ controller_host }}"
28+
vars:
29+
# NOTE: Without this, the controller's ansible_host variable will not
30+
# be respected when using delegate_to.
31+
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
32+
environment: "{{ openstack_auth_env }}"
33+
block:
34+
35+
- name: Show baremetal node
36+
ansible.builtin.command:
37+
cmd: "{{ venv }}/bin/openstack baremetal node show {{ inventory_hostname }} -f json"
38+
register: node_show
39+
failed_when:
40+
- node_show.rc != 0
41+
changed_when: false
42+
43+
- name: Check if bmc is up
44+
ansible.builtin.set_fact:
45+
kayobe_bmc_up: "{{ (node_show.stdout | from_json)['extra'].get('kayobe_bmc_up') }}"
46+
provision_state: "{{ (node_show.stdout | from_json)['provision_state'] }}"
47+
48+
- name: Output when bmc last up run
49+
ansible.builtin.debug:
50+
msg: "BMC for node {{ inventory_hostname }} was up at {{ kayobe_bmc_up }}."
51+
when: kayobe_bmc_up != ""
52+
53+
- name: Check BMC is up
54+
ansible.builtin.uri:
55+
url: "https://{{ ironic_driver_info['redfish_address'] }}"
56+
method: GET
57+
status_code: 200
58+
validate_certs: false
59+
timeout: 10
60+
61+
- name: Get firmware inventory (to check redfish auth)
62+
community.general.redfish_info:
63+
category: Update
64+
command: GetFirmwareInventory
65+
baseuri: "{{ ironic_redfish_address }}"
66+
username: "{{ ironic_redfish_username }}"
67+
password: "{{ ironic_redfish_password }}"
68+
register: firmware_inventory
69+
failed_when: not firmware_inventory.redfish_facts.firmware.ret
70+
71+
# - name: Print fetched information
72+
# ansible.builtin.debug:
73+
# msg: "{{ firmware_inventory.redfish_facts.firmware | to_nice_json }}"
74+
75+
- name: Reboot BMC
76+
community.general.redfish_command:
77+
category: Manager
78+
command: PowerReboot
79+
resource_id: 1
80+
baseuri: "{{ ironic_redfish_address }}"
81+
username: "{{ ironic_redfish_username }}"
82+
password: "{{ ironic_redfish_password }}"
83+
when: kayobe_bmc_up == ""
84+
85+
- name: Wait 300 seconds for port 443 to become open
86+
ansible.builtin.wait_for:
87+
port: 443
88+
host: "{{ ironic_redfish_address }}"
89+
delay: 20
90+
timeout: 300
91+
when: kayobe_bmc_up == ""
92+
93+
- name: Check BMC back up again
94+
ansible.builtin.uri:
95+
url: "https://{{ ironic_driver_info['redfish_address'] }}"
96+
method: GET
97+
status_code: 200
98+
validate_certs: false
99+
timeout: 10
100+
register: uri_output
101+
until: uri_output.status == 200
102+
delay: 5
103+
retries: 24 # Retries for 24 * 5 seconds = 120 seconds = 2 minutes
104+
105+
- name: Note when we are able to reach the bmc, the first time
106+
ansible.builtin.command:
107+
cmd: |
108+
{{ venv }}/bin/openstack baremetal node set {{ inventory_hostname }} --extra kayobe_bmc_up={{ now(utc=true, fmt='%Y-%m-%dT%H:%M:%SZ') }}
109+
register: node_set
110+
failed_when:
111+
- node_set.rc != 0
112+
changed_when: true
113+
when: kayobe_bmc_up == ""
114+
115+
- name: Try move from enroll to manageable
116+
ansible.builtin.command:
117+
cmd: |
118+
{{ venv }}/bin/openstack baremetal node manage {{ inventory_hostname }} --wait 300
119+
register: node_set
120+
failed_when:
121+
- node_set.rc != 0
122+
changed_when: true
123+
when:
124+
- provision_state == "enroll"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
- name: Check baremetal compute node bmc is up
3+
hosts: baremetal
4+
gather_facts: false
5+
max_fail_percentage: >-
6+
{{ baremetal_compute_register_max_fail_percentage |
7+
default(baremetal_compute_max_fail_percentage) |
8+
default(kayobe_max_fail_percentage) |
9+
default(100) }}
10+
tags:
11+
- baremetal
12+
vars:
13+
venv: "{{ virtualenv_path }}/openstack-cli"
14+
controller_host: localhost
15+
16+
tasks:
17+
- name: Show and check baremetal node
18+
delegate_to: "{{ controller_host }}"
19+
vars:
20+
# NOTE: Without this, the controller's ansible_host variable will not
21+
# be respected when using delegate_to.
22+
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
23+
redfish_inspect_timeout: 120
24+
environment: "{{ openstack_auth_env }}"
25+
block:
26+
27+
- name: Show baremetal node
28+
ansible.builtin.command:
29+
cmd: "{{ venv }}/bin/openstack baremetal node show {{ inventory_hostname }} -f json"
30+
register: node_show
31+
failed_when:
32+
- node_show.rc != 0
33+
changed_when: false
34+
35+
- name: Check BMC is up
36+
ansible.builtin.uri:
37+
url: "https://{{ ironic_driver_info['redfish_address'] }}"
38+
method: GET
39+
status_code: 200
40+
validate_certs: false
41+
timeout: 10
42+
43+
- name: Check for redfish inspection details
44+
ansible.builtin.set_fact:
45+
kayobe_redfish_inspect_done: "{{ (node_show.stdout | from_json)['extra'].get('kayobe_redfish_inspect_done') }}"
46+
inspect_interface: "{{ (node_show.stdout | from_json)['inspect_interface'] }}"
47+
provision_state: "{{ (node_show.stdout | from_json)['provision_state'] }}"
48+
49+
- name: Output when redfish inspection was done
50+
ansible.builtin.debug:
51+
msg: "{{ inventory_hostname }} inspected at {{ kayobe_redfish_inspect_done }}."
52+
when: kayobe_redfish_inspect_done != ""
53+
54+
- name: Fail if not redfish inspection
55+
ansible.builtin.fail:
56+
msg: "{{ inventory_hostname }} has the wrong inspect_interface: {{ inspect_interface }}"
57+
when:
58+
- inspect_interface != "redfish"
59+
- kayobe_redfish_inspect_done == ""
60+
61+
- name: Fail if not in manageable state
62+
ansible.builtin.fail:
63+
msg: "{{ inventory_hostname }} has the wrong provision_state: {{ provision_state }}"
64+
when:
65+
- provision_state != "manageable"
66+
- kayobe_redfish_inspect_done == ""
67+
68+
- name: Wait for inspection
69+
ansible.builtin.command:
70+
cmd: |
71+
{{ venv }}/bin/openstack baremetal node inspect {{ inventory_hostname }} --wait {{ redfish_inspect_timeout }}
72+
register: node_inspect
73+
failed_when:
74+
- node_inspect.rc != 0
75+
changed_when: true
76+
when: kayobe_redfish_inspect_done == ""
77+
78+
- name: Note when redfish inspection is done
79+
ansible.builtin.command:
80+
cmd: |
81+
{{ venv }}/bin/openstack baremetal node set {{ inventory_hostname }} --extra kayobe_redfish_inspect_done={{ now(utc=true, fmt='%Y-%m-%dT%H:%M:%SZ') }}
82+
register: node_set
83+
failed_when:
84+
- node_set.rc != 0
85+
changed_when: true
86+
when: kayobe_redfish_inspect_done == ""

0 commit comments

Comments
 (0)