/
ovb-create-stack.yml
174 lines (142 loc) · 6.79 KB
/
ovb-create-stack.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
---
- name: Generate idnum for all run-related entities
set_fact:
idnum: >-
{% if 'change' in zuul|default({}) and 'patchset' in zuul|default({}) -%}
{{ zuul.change }}_{{ zuul.patchset }}_{% endif %}{{ tmp.idnum }}
- name: Dump idnum for later stack deletion
copy:
content: "{{ idnum }}"
dest: "{{ ovb_working_dir }}/idnum"
- name: Generate OVB parameters template
include: generate_template.yml
- name: Find out undercloud host ID
include: find_undercloud_uuid.yml
when: attach_to_ovb_networks|bool
- name: Generate clouds.yaml file
include_tasks: ovb-clouds-config.yml
when: create_clouds_yaml|bool
- name: Install heat stack
# notest tells molecule to skip during functional testing
tags: notest
block:
- name: Create a key in case of extranode
shell: |
ssh-keygen -N "" -f ~/extranode-id_rsa;
{{ ovb_working_dir }}/.venv/bin/openstack keypair create --public-key ~/extranode-id_rsa.pub {{ extra_node_key_name }}-{{ idnum }};
when:
- extra_node|bool
- extra_node_create_key|bool
- name: Create a stack
command: |
{{ ovb_working_dir }}/.venv/bin/python {{ ovb_repo_directory }}/bin/deploy.py {{ ovb_args }}
args:
chdir: "{{ ovb_repo_directory }}"
- name: Wait until stack is created or failed
command: >-
{{ ovb_working_dir }}/.venv/bin/openstack stack show {{ stack_name }} -f yaml
register: result
until: ("COMPLETE" in result.stdout) or ("FAILED" in result.stdout) or result.rc != 0
retries: 18
delay: 100
changed_when: false
- name: Dump stderr in case of command failure
debug:
msg: "{{ result.stderr }}"
when: result.rc != 0
- name: Dump failed stack
shell: |
{{ ovb_working_dir }}/.venv/bin/openstack stack show {{ stack_name }} 2>&1 | tee {{ failed_log }}
{{ ovb_working_dir }}/.venv/bin/openstack stack failures list --long {{ stack_name }} >> {{ failed_log }} 2>&1
when: '"FAILED" in result.stdout'
- name: Show stack status
command: >-
{{ ovb_working_dir }}/.venv/bin/openstack stack show {{ stack_name }} -f yaml
- name: Fail if stack did not deploy successfully
fail:
msg: "Stack {{ stack_name }} did not deploy successfully. See the stack status message above."
when: '"CREATE_COMPLETE" not in result.stdout'
- name: Return floating ip outputs
command: >
{{ ovb_working_dir }}/.venv/bin/openstack stack show {{ stack_name }} -f json -c outputs
register: stack_outputs
- name: Find ID of provision network
command: "{{ ovb_working_dir }}/.venv/bin/openstack network show ctlplane-{{ idnum }} -f value -c id"
register: provision_id
- name: Find ID of public network
command: "{{ ovb_working_dir }}/.venv/bin/openstack network show public-{{ idnum }} -f value -c id"
register: public_id
when: net_iso and net_iso != 'none'
- name: Attach instance to provision OVB network
command: "{{ ovb_working_dir }}/.venv/bin/openstack server add network {{ undercloud_uuid }} {{ provision_id.stdout }}"
when: attach_to_ovb_networks|bool
- name: Attach instance to public OVB network
command: "{{ ovb_working_dir }}/.venv/bin/openstack server add network {{ undercloud_uuid }} {{ public_id.stdout }}"
when: net_iso and net_iso != 'none' and attach_to_ovb_networks|bool
- name: Attach private network to undercloud
when:
- create_private_network|bool
- attach_to_ovb_networks|bool
block:
- name: Find ID of private network
command: "{{ ovb_working_dir }}/.venv/bin/openstack network show private-{{ idnum }} -f value -c id"
register: private_id
- name: Attach instance to private OVB network
command: "{{ ovb_working_dir }}/.venv/bin/openstack server add network {{ undercloud_uuid }} {{ private_id.stdout }}"
- name: Find ports in private network
command: "{{ ovb_working_dir }}/.venv/bin/openstack port list --network {{ private_id.stdout }} --server {{ undercloud_uuid }} -f value -c ID"
register: private_port
- name: Disable security in private ports
command: "{{ ovb_working_dir }}/.venv/bin/openstack port set {{ private_port.stdout }} --no-security-group --disable-port-security"
- name: Find ports in provision network
command: "{{ ovb_working_dir }}/.venv/bin/openstack port list --network {{ provision_id.stdout }} --server {{ undercloud_uuid }} -f value -c ID"
register: provision_port
when: attach_to_ovb_networks|bool
- name: Find ports in public network
command: "{{ ovb_working_dir }}/.venv/bin/openstack port list --network {{ public_id.stdout }} --server {{ undercloud_uuid }} -f value -c ID"
register: public_port
when: net_iso and net_iso != 'none' and attach_to_ovb_networks|bool
- name: Disable security in provision ports
command: "{{ ovb_working_dir }}/.venv/bin/openstack port set {{ provision_port.stdout }} --no-security-group --disable-port-security"
when: attach_to_ovb_networks|bool
- name: Disable security in public ports
command: "{{ ovb_working_dir }}/.venv/bin/openstack port set {{ public_port.stdout }} --no-security-group --disable-port-security"
when: net_iso and net_iso != 'none' and attach_to_ovb_networks|bool
- name: Build nodes.json file to be used as instackenv.json
shell: >
{{ ovb_working_dir }}/.venv/bin/python {{ ovb_repo_directory }}/bin/build-nodes-json
--env {{ ovb_repo_directory }}/env-{{ idnum }}.yaml
--network_details
--nodes_json {{ nodes_file }}
{% if ovb_repo_version != 'stable/1.0' %} --physical_network --id {{ idnum }} {% endif %}
args:
chdir: "{{ ovb_working_dir }}"
register: nodes_json
changed_when: true
always:
- name: Show last stack status
command: >-
{{ ovb_working_dir }}/.venv/bin/openstack stack show {{ stack_name }} -f yaml
changed_when: false
failed_when: false
- name: Delete CREATE_FAILED stack
shell: |
{{ ovb_working_dir }}/.venv/bin/openstack stack delete {{ stack_name }} -y
{{ ovb_working_dir }}/.venv/bin/openstack stack delete {{ stack_name }}-extra -y
when: '"CREATE_FAILED" in result.stdout'
failed_when: false
- name: Stack is timed out if not created within half hour
debug:
msg: "Stack failed to create with given timeout: {{ stack_name }}"
when:
- '"COMPLETE" not in result.stdout'
- '"FAILED" not in result.stdout'
failed_when: false
- name: remove clouds.yaml file
file:
path: "{{ clouds_yaml }}"
state: absent
when: create_clouds_yaml|bool
environment:
- OS_CLIENT_CONFIG_FILE: "{{ clouds_yaml }}"
- OS_CLOUD: "{{ cloud_name }}"