/
ceph_auth_extra_compute.yml
227 lines (207 loc) · 6.94 KB
/
ceph_auth_extra_compute.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
---
# Copyright 2016, Walmart Stores, 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: Create key files for nova_compute on extra cluster(s)
shell: >-
ceph auth get-key client.{{ item.client_name }} --cluster {{ ceph_cluster_name }}
> /etc/ceph/{{ ceph_cluster_name }}.client.{{ item.client_name }}.key.tmp
with_items: "{{ ceph_extra_confs }}"
changed_when: false
delegate_to: "{{ item.mon_host }}"
when:
- item.client_name is defined
- item.mon_host is defined
- name: Get extra key files
command: >-
scp {{ item.mon_host }}:/etc/ceph/{{ ceph_cluster_name }}.client.{{ item.client_name }}.key.tmp
/tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp
changed_when: false
delegate_to: localhost
with_items: "{{ ceph_extra_confs }}"
when:
- item.mon_host is defined
- item.client_name is defined
- name: Distribute extra key files from monitor host
copy:
src: "/tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp"
dest: "/tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp"
mode: "0640"
with_items: "{{ ceph_extra_confs }}"
when:
- item.mon_host is defined
- item.client_name is defined
- name: Create extra key files from keyring files
copy:
src: "{{ item.keyring_src }}"
dest: "/tmp/{{ item.secret_uuid }}{{ item.client_name }}.key.tmp"
mode: "0640"
with_items: "{{ ceph_extra_confs }}"
when:
- item.keyring_src is defined
- item.client_name is defined
- item.secret_uuid is defined
- name: Remove temp extra key files
file:
path: "/etc/ceph/{{ ceph_cluster_name }}.client.{{ item.client_name }}.key.tmp"
state: absent
delegate_to: "{{ item.mon_host }}"
with_items: "{{ ceph_extra_confs }}"
when:
- item.mon_host is defined
- item.keyring_src is defined
- item.client_name is defined
- name: Provide extra xml files to create the secrets
template:
src: secret.xml.j2
dest: /tmp/{{ item.secret_uuid }}{{ item.client_name }}-secret.xml
mode: "0600"
with_items: "{{ ceph_extra_confs }}"
when:
- item.client_name is defined
- item.secret_uuid is defined
- name: Check if extra secret(s) are defined in libvirt pt1
shell: "virsh secret-dumpxml {{ item.secret_uuid }} 2>&1 >/dev/null && touch /tmp/{{ item.secret_uuid }}.libvirt_secret_exists"
changed_when: false
failed_when: false
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
tags:
- always
- name: Check if extra secret(s) are defined in libvirt pt2
shell: "ls /tmp | grep \\.libvirt_secret_exists | awk -F'.' '{print $1}'"
changed_when: false
failed_when: false
register: libvirt_secret_exists
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
tags:
- always
- name: Define libvirt nova extra secret(s)
command: "virsh secret-define --file /tmp/{{ item.secret_uuid }}{{ item.client_name }}-secret.xml"
changed_when: false
loop: "{{ ceph_extra_confs }}"
loop_control:
index_var: index
when:
- "'client_name' in item"
- "'secret_uuid' in item"
- item.secret_uuid not in libvirt_secret_exists.results[index].stdout_lines
notify:
- Restart os services
- name: Check if extra secret values are set in libvirt pt1
shell: "virsh secret-get-value {{ item.secret_uuid }} 2>&1 >/dev/null && touch /tmp/{{ item.secret_uuid }}.libvirt_secret_value_exists "
changed_when: false
failed_when: false
register: libvirt_nova_set
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
- name: Check if extra secret values are set in libvirt pt2
shell: "ls /tmp | grep \\.libvirt_secret_value_exists | awk -F'.' '{print $1}'"
changed_when: false
failed_when: false
register: libvirt_secret_value_exists
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
tags:
- always
- name: Set extra secret value(s) in libvirt from monitor host # noqa: no-changed-when
shell: "virsh secret-set-value --secret {{ item.secret_uuid }} --base64 $(cat /tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp)"
loop: "{{ ceph_extra_confs }}"
loop_control:
index_var: index
when:
- "'client_name' in item"
- "'mon_host' in item"
- "'secret_uuid' in item"
- item.secret_uuid not in libvirt_secret_value_exists.results[index].stdout_lines
notify:
- Restart os services
- name: Set extra secret value(s) in libvirt from keyring # noqa: no-changed-when
shell: >-
virsh secret-set-value --secret {{ item.secret_uuid }} --base64
$(awk '/key = /{print $3}' /tmp/{{ item.secret_uuid }}{{ item.client_name }}.key.tmp)
loop: "{{ ceph_extra_confs }}"
loop_control:
index_var: index
when:
- "'client_name' in item"
- "'keyring_src' in item"
- "'secret_uuid' in item"
- item.secret_uuid not in libvirt_secret_value_exists.results[index].stdout_lines
notify:
- Restart os services
# Cleanup temp files
- name: Remove libvirt nova secret detection file
file:
path: "/tmp/{{ item.secret_uuid }}.libvirt_secret_exists"
state: "absent"
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
tags:
- always
- name: Remove libvirt nova secret value detection file
file:
path: "/tmp/{{ item.secret_uuid }}.libvirt_secret_value_exists"
state: "absent"
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
tags:
- always
- name: Remove libvirt nova secret file
file:
path: "/tmp/{{ item.secret_uuid }}{{ item.client_name }}-secret.xml"
state: "absent"
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
- item.client_name is defined
tags:
- always
- name: Remove libvirt key file from monitor host
file:
path: "/tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp"
state: "absent"
with_items: "{{ ceph_extra_confs }}"
when:
- item.mon_host is defined
- item.client_name is defined
tags:
- always
- name: Remove libvirt key file from keyring
file:
path: "/tmp/{{ item.secret_uuid }}{{ item.client_name }}.key.tmp"
state: "absent"
with_items: "{{ ceph_extra_confs }}"
when:
- item.secret_uuid is defined
- item.client_name is defined
tags:
- always
- name: Remove libvirt key file localhost
file:
path: "/tmp/{{ item.mon_host }}{{ item.client_name }}.key.tmp"
state: "absent"
delegate_to: localhost
when:
- item.mon_host is defined
- item.client_name is defined
with_items: "{{ ceph_extra_confs }}"
tags:
- always