-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.yml
244 lines (217 loc) · 11 KB
/
tag.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
- name: Tag our machines with flavors
hosts: undercloud
gather_facts: no
any_errors_fatal: true
tasks:
- name: Use instackenv provided
vars:
instack_input: "{{ (install.instackenv|default({})).file | default('') }}"
stat:
path: "~/{{ (instack_input or '~/instackenv.json') | basename }}"
register: instack_file_path
- set_fact:
instack_file: "{{ instack_file_path.stat.path }}"
when: instack_file_path.stat.exists
- name: fail if instackenv file is missing
fail:
msg: "instackenv file is missing"
when: not instack_file_path.stat.exists
# replace with os_ modules once shade group will be available
- name: read all flavors
shell: |
source ~/stackrc
openstack flavor list | awk 'FNR>3 {print $4}' | sed '/^\s*$/d'
register: existing_flavors
tags: skip_ansible_lint
- name: remove all the flavors
shell: |
source ~/stackrc
openstack flavor delete {{ item }}
with_items: "{{ existing_flavors.stdout_lines }}"
ignore_errors: yes
tags: skip_ansible_lint
register: flavor_delete
- name: Workarond for BZ #1317312
shell: |
source ~/stackrc
nova flavor-delete {{ item[0] }}
tags: skip_ansible_lint
when: "'public endpoint for messaging service not found' in item[1].stderr "
with_together:
- "{{ existing_flavors.stdout_lines }}"
- "{{ flavor_delete.results }}"
ignore_errors: yes
- name: create the baremetal flavor for our machines
shell: |
source ~/stackrc
openstack flavor create --id auto --ram 4096 --disk 8 --vcpus 1 baremetal
tags: skip_ansible_lint
register: bm_result
ignore_errors: yes
failed_when: "bm_result.rc != 0 and bm_result.stderr.find('Flavor with name baremetal already exists') != -1"
- name: set resources properties for baremetal flavor(RHOS14+)
shell: |
source ~/stackrc
openstack flavor set baremetal \
--property resources:CUSTOM_BAREMETAL=1 \
--property resources:DISK_GB=0 \
--property resources:MEMORY_MB=0 \
--property resources:VCPU=0 \
--property capabilities:boot_option=local
tags: skip_ansible_lint
when: install.version|default(undercloud_version)|openstack_release > 13
# OSPd7 doesn't seem to have implicit profile matching and notifies to do this step manually
# in prior of OC deployment. Otherwise errors and warnings are produced in process when
# overcloud deployment starts.
- name: set additional properties
shell: |
source ~/stackrc
openstack flavor set --property 'cpu_arch'='x86_64' --property 'capabilities:boot_option'='local' --property "capabilities:profile"="baremetal" baremetal
when:
- install.version|default(undercloud_version)|openstack_release == 7
- "'hypervisor' not in groups"
- "'bmc' not in groups"
tags: skip_ansible_lint
- name: Set baremetal capability for OSPd7 nodes as it must be done explicitely
shell: |
source ~/stackrc
for node in `ironic node-list | awk '{print $2}' | grep -v "\(ID\|^$\)"`; do ironic node-update $node add properties/capabilities=profile:baremetal,boot_option:local; done
tags: skip_ansible_lint
when:
- install.version|default(undercloud_version)|openstack_release == 7
- "'hypervisor' not in groups"
- "'bmc' not in groups"
- name: read instackenv file
command: cat "{{ instack_file }}"
register: overcloud_hosts_facts
- set_fact:
overcloud_facts: "{{ overcloud_hosts_facts.stdout | from_json }}"
- block:
- name: check for original flavors
shell: >
source ~/stackrc;
openstack flavor list | awk '/{{ item.name.rstrip('1234567890-').split('-')[-1] }}/ {print $4}'
with_items: "{{ overcloud_facts.nodes | default([]) }}"
register: original_flavors
# Remember, hostvars are special: https://github.com/ansible/ansible/issues/13838, https://github.com/ansible/ansible/issues/21084
- name: create the flavors for our machines
vars:
flv_min_disk_size: 6
flv_min_cpu: 1
searched_string: "Flavor with name {{ item.name }} already exists"
shell: >
source ~/stackrc;
openstack flavor create
--id auto
--ram {{ (hostvars[item.name] | default({})).ram | default(item.memory) }}
--disk {{ [((hostvars[item.name] | default({})).disk | default(item.disk) | int) - 3, flv_min_disk_size] | max }}
--vcpus {{ [((hostvars[item.name] | default({})).vcpus | default(item.cpu) | int) - 1, flv_min_cpu] | max }}
{{ item.name.rstrip('1234567890-').split('-')[-1] }}
register: flavor_result
failed_when: flavor_result.rc != 0 and flavor_result.stderr.find(searched_string) != -1
with_items: "{{ overcloud_facts.nodes | default([]) }}"
- name: get the node UUID
vars:
ironic_cli: "{{ (install.version|default(undercloud_version)|openstack_release < 14)|ternary('ironic node-list','openstack baremetal node list') }}"
shell: |
source ~/stackrc
{{ ironic_cli }} | awk '/{{ item.name | default(item) }}/ {print $2}'
with_items: "{{ overcloud_facts.nodes | default([])}}"
register: node_list
when: "overcloud_facts.nodes[0].name is defined"
- set_fact:
tagged_flavors: "{{ flavor_result.results }}"
- name: set additional properties
shell: |
source ~/stackrc
openstack flavor set \
--property 'cpu_arch'='x86_64' \
--property 'capabilities:boot_option'='local' \
--property 'capabilities:profile'='{{ item.cmd.split() | last }}' {{ item.cmd.split() | last }} \
{% if install.boot.mode == 'uefi' %}--property capabilities:boot_mode=uefi{% endif %}
tags: skip_ansible_lint
when: item.cmd is defined
with_items: "{{ tagged_flavors | default([]) }}"
- name: tag our nodes with the proper profile with ironic client
shell: |
source ~/stackrc
ironic node-update {{ item[0].stdout }} \
add properties/capabilities='profile:{{ item[1].cmd.split() | last }},{% if install.boot.mode == 'uefi' %}boot_mode:uefi,{% endif %}boot_option:local,node:{{ item[0].item.name }}'
tags: skip_ansible_lint
when:
- "item[0].item.name is defined and item[1].cmd is defined and item[0].item.name.rstrip('1234567890-').split('-')[-1] in item[1].cmd"
- install.version|default(undercloud_version)|openstack_release < 14
with_together:
- "{{ node_list.results }}"
- "{{ tagged_flavors | default([]) }}"
- name: tag our nodes with the proper profile with unified client
shell: |
source ~/stackrc
openstack baremetal node set \
--property capabilities='profile:{{ item[1].cmd.split() | last }},{% if install.boot.mode == 'uefi' %}boot_mode:uefi,{% endif %}boot_option:local,node:{{ item[0].item.name }}' {{ item[0].stdout }}
tags: skip_ansible_lint
when:
- "item[0].item.name is defined and item[1].cmd is defined and item[0].item.name.rstrip('1234567890-').split('-')[-1] in item[1].cmd"
- install.version|default(undercloud_version)|openstack_release >= 14
with_together:
- "{{ node_list.results }}"
- "{{ tagged_flavors | default([]) }}"
- name: Check if node name is not None
shell: |
source ~/stackrc
openstack baremetal node list -c Name -f value|grep -zqvi None
register: check_nodename
failed_when: false
changed_when: false
- name: Print resource-class debug message
vars:
message: |
Currently custom resource class(es) is available only for the
virtual deployment, since node name is used to associate custom
resource class with it and when node name is 'None'
scheduling based on resource class is skipping
debug:
msg: "{{ message.split('\n') }}"
when: check_nodename.rc != 0
- block:
- name: Set default resource-class parameters
vars:
name: "{{ item.name.rstrip('1234567890-').split('-')[-1] }}"
set_fact:
default_resource_class: "{{ default_resource_class | default([]) + [{ 'name': name, 'flavor': name, 'node': item.name }] }}"
with_items: "{{ overcloud_facts.nodes | default([])}}"
tags: skip_ansible_lint
when:
- "overcloud_facts.nodes[0].name is defined"
- name: Merge default and override resource class parameters
set_fact:
resource_class: "{{ default_resource_class + install.resource.class.get('override', []) }}"
- name: Add resource class to flavor and node
shell: |
set -exo pipefail
REGEX=".*-[0-9]+$"
source ~/stackrc
# Remove already exist custom resource class for flavor
for rclass in $(openstack flavor show {{ item.flavor }} -f value -c properties | grep -o 'CUSTOM_[A-Z_]*'); do
openstack flavor unset {{ item.flavor }} --property resources:${rclass}
done
openstack flavor set {{ item.flavor }} \
--property resources:DISK_GB=0 \
--property resources:MEMORY_MB=0 \
--property resources:VCPU=0 \
--property resources:CUSTOM_{{ item.name.replace('-', '_').upper() }}=1
{% for node in item.node.split(':') %}
if [[ "{{ node }}" =~ $REGEX ]]; then
openstack baremetal node set $(openstack baremetal node show {{ node }} -c uuid -f value) \
--resource-class {{ item.name }}
else
openstack baremetal node list|awk '/{{ node }}/ {print $2}'| \
xargs -I{} openstack baremetal node set {} --resource-class {{ item.name }}
fi
{% endfor %}
tags: skip_ansible_lint
with_items: "{{ resource_class }}"
when:
- check_nodename.rc == 0
- install.resource.class.enabled
- install.version|default(undercloud_version)|openstack_release >= 12