Skip to content

Commit 6967c27

Browse files
zerwesKlaus Zerweswidhalmt
authored
use ansible DEFAULT_LOCAL_TMP for files stored on the ansible controller (#355)
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-local-tmp closes #354 --------- Co-authored-by: Klaus Zerwes <Klaus.Zerwes@rosalux.org> Co-authored-by: Thomas Widhalm <widhalmt@widhalm.or.at>
1 parent 8ed5180 commit 6967c27

File tree

4 files changed

+43
-43
lines changed

4 files changed

+43
-43
lines changed

roles/beats/tasks/beats-security.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@
8787
block:
8888
- name: Check the existance of cert on localhost
8989
ansible.builtin.stat:
90-
path: /tmp/{{ ansible_hostname }}-beats.zip
90+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip"
9191
register: beats_check_temporary_cert
9292

9393
- name: Move temporary zip file
9494
ansible.builtin.copy:
95-
src: /tmp/{{ ansible_hostname }}-beats.zip
96-
dest: "/tmp/{{ ansible_hostname }}-beats.zip_{{ ansible_date_time.iso8601_micro }}"
95+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip"
96+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip_{{ ansible_date_time.iso8601_micro }}"
9797
mode: preserve
9898
when: beats_check_temporary_cert.stat.exists
9999
register: beats_move_cert_file
100100

101101
- name: Remove temporary cert file
102102
ansible.builtin.file:
103-
path: /tmp/{{ ansible_hostname }}-beats.zip
103+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip"
104104
state: absent
105105
when: beats_move_cert_file.changed
106106

@@ -139,7 +139,7 @@
139139
- name: Fetch certificate from ca host to master
140140
ansible.builtin.fetch:
141141
src: "{{ elasticstack_ca_dir }}/{{ ansible_hostname }}-beats.zip"
142-
dest: "/tmp/{{ ansible_hostname }}-beats.zip"
142+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip"
143143
flat: yes
144144
delegate_to: "{{ elasticstack_ca }}"
145145
tags:
@@ -149,7 +149,7 @@
149149

150150
- name: Copy the certificate to actual node
151151
ansible.builtin.unarchive:
152-
src: "/tmp/{{ ansible_hostname }}-beats.zip"
152+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-beats.zip"
153153
dest: "/etc/beats/certs/"
154154
owner: root
155155
group: root
@@ -196,7 +196,7 @@
196196
- name: Fetch ca certificate from ca host to master
197197
ansible.builtin.fetch:
198198
src: "{{ elasticstack_ca_dir }}/ca.crt"
199-
dest: /tmp/ca.crt
199+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
200200
flat: yes
201201
delegate_to: "{{ elasticstack_ca }}"
202202
tags:
@@ -206,7 +206,7 @@
206206

207207
- name: Copy the ca certificate to actual node
208208
ansible.builtin.copy:
209-
src: /tmp/ca.crt
209+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
210210
dest: /etc/beats/certs
211211
owner: root
212212
group: root

roles/elasticsearch/tasks/elasticsearch-security.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@
7474

7575
- name: Check the existance of ca on Ansible controler
7676
ansible.builtin.stat:
77-
path: /tmp/ca.crt
77+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
7878
register: elasticsearch_check_temporary_ca
7979
delegate_to: localhost
8080

8181
- name: Move temporary ca file on Ansible controler
8282
ansible.builtin.copy:
83-
src: /tmp/ca.crt
84-
dest: "/tmp/ca.crt_{{ ansible_date_time.iso8601_micro }}"
83+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
84+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt_{{ ansible_date_time.iso8601_micro }}"
8585
mode: preserve
8686
when: elasticsearch_check_temporary_ca.stat.exists
8787
delegate_to: localhost
8888
register: elasticsearch_move_ca_file
8989

9090
- name: Remove temporary ca file on Ansible controler
9191
ansible.builtin.file:
92-
path: /tmp/ca.crt
92+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
9393
state: absent
9494
when: elasticsearch_move_ca_file.changed
9595
delegate_to: localhost
@@ -185,20 +185,20 @@
185185
block:
186186
- name: Check the existance of cert on Ansible controler
187187
ansible.builtin.stat:
188-
path: /tmp/{{ ansible_hostname }}.p12
188+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12"
189189
register: elasticsearch_check_temporary_cert
190190

191191
- name: Move temporary cert on Ansible controler
192192
ansible.builtin.copy:
193-
src: /tmp/{{ ansible_hostname }}.p12
194-
dest: "/tmp/{{ ansible_hostname }}.p12_{{ ansible_date_time.iso8601_micro }}"
193+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12"
194+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12_{{ ansible_date_time.iso8601_micro }}"
195195
mode: preserve
196196
when: elasticsearch_check_temporary_cert.stat.exists
197197
register: elasticsearch_move_cert_file
198198

199199
- name: Remove temporary cert on Ansible controler
200200
ansible.builtin.file:
201-
path: /tmp/{{ ansible_hostname }}.p12
201+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12"
202202
state: absent
203203
when: elasticsearch_move_cert_file.changed
204204

@@ -264,7 +264,7 @@
264264
- name: Fetch ca certificate from ca host to Ansible controller
265265
ansible.builtin.fetch:
266266
src: "{{ elasticstack_ca_dir }}/ca.crt"
267-
dest: /tmp/ca.crt
267+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
268268
flat: yes
269269
when: inventory_hostname == elasticstack_ca
270270
tags:
@@ -275,7 +275,7 @@
275275
- name: Fetch certificate from ca host to Ansible controller
276276
ansible.builtin.fetch:
277277
src: "{{ elasticstack_ca_dir }}/{{ ansible_hostname }}.p12"
278-
dest: "/tmp/{{ ansible_hostname }}.p12"
278+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12"
279279
flat: yes
280280
delegate_to: "{{ elasticstack_ca }}"
281281
tags:
@@ -297,7 +297,7 @@
297297

298298
- name: Copy the ca certificate to elasticsearch nodes
299299
ansible.builtin.copy:
300-
src: /tmp/ca.crt
300+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
301301
dest: "/etc/elasticsearch/certs"
302302
owner: root
303303
group: elasticsearch
@@ -313,7 +313,7 @@
313313

314314
- name: Copy the certificate to elasticsearch nodes
315315
ansible.builtin.copy:
316-
src: "/tmp/{{ ansible_hostname }}.p12"
316+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}.p12"
317317
dest: "/etc/elasticsearch/certs"
318318
owner: root
319319
group: elasticsearch

roles/kibana/tasks/kibana-security.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@
9191
block:
9292
- name: Check the existance of cert on localhost
9393
ansible.builtin.stat:
94-
path: /tmp/{{ ansible_hostname }}-kibana.p12
94+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12"
9595
register: kibana_check_temporary_cert
9696

9797
- name: Move temporary cert file
9898
ansible.builtin.copy:
99-
src: /tmp/{{ ansible_hostname }}-kibana.p12
100-
dest: "/tmp/{{ ansible_hostname }}-kibana.p12_{{ ansible_date_time.iso8601_micro }}"
99+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12"
100+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12_{{ ansible_date_time.iso8601_micro }}"
101101
mode: preserve
102102
when: kibana_check_temporary_cert.stat.exists
103103
register: kibana_move_cert_file
104104

105105
- name: Remove temporary cert file
106106
ansible.builtin.file:
107-
path: /tmp/{{ ansible_hostname }}-kibana.p12
107+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12"
108108
state: absent
109109
when: kibana_move_cert_file.changed
110110

@@ -180,7 +180,7 @@
180180
- name: Fetch certificate from ca host to master
181181
ansible.builtin.fetch:
182182
src: "{{ elasticstack_ca_dir }}/{{ ansible_hostname }}-kibana.p12"
183-
dest: "/tmp/"
183+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12"
184184
flat: yes
185185
delegate_to: "{{ elasticstack_ca }}"
186186
tags:
@@ -190,7 +190,7 @@
190190

191191
- name: Copy the certificate to actual node
192192
ansible.builtin.copy:
193-
src: "/tmp/{{ ansible_hostname }}-kibana.p12"
193+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-kibana.p12"
194194
dest: "/etc/kibana/certs"
195195
owner: root
196196
group: kibana
@@ -215,7 +215,7 @@
215215
- name: Fetch ca certificate from ca host to master
216216
ansible.builtin.fetch:
217217
src: "{{ elasticstack_ca_dir }}/ca.crt"
218-
dest: /tmp/ca.crt
218+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
219219
flat: yes
220220
delegate_to: "{{ elasticstack_ca }}"
221221
tags:
@@ -225,7 +225,7 @@
225225

226226
- name: Copy the ca certificate to actual node
227227
ansible.builtin.copy:
228-
src: /tmp/ca.crt
228+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
229229
dest: /etc/kibana/certs
230230
owner: root
231231
group: kibana

roles/logstash/tasks/logstash-security.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,39 +114,39 @@
114114
block:
115115
- name: Check the existance of cert on Ansible controler
116116
ansible.builtin.stat:
117-
path: /tmp/{{ ansible_hostname }}-ls.p12
117+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
118118
register: logstash_check_temporary_cert_ansible_controler
119119

120120
- name: Move temporary cert file on Ansible controler
121121
ansible.builtin.copy:
122-
src: /tmp/{{ ansible_hostname }}-ls.p12
123-
dest: "/tmp/{{ ansible_hostname }}-ls.p12_{{ ansible_date_time.iso8601_micro }}"
122+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
123+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12_{{ ansible_date_time.iso8601_micro }}"
124124
mode: preserve
125125
when: logstash_check_temporary_cert_ansible_controler.stat.exists
126126
register: logstash_move_cert_file_ansible_controler
127127

128128
- name: Remove temporary cert file on Ansible controler
129129
ansible.builtin.file:
130-
path: /tmp/{{ ansible_hostname }}-ls.p12
130+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
131131
state: absent
132132
when: logstash_move_cert_file_ansible_controler.changed
133133

134134
- name: Check the existance of cert zip file on Ansible controler
135135
ansible.builtin.stat:
136-
path: /tmp/{{ ansible_hostname }}-ls.zip
136+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip"
137137
register: logstash_check_temporary_cert_zip_ansible_controler
138138

139139
- name: Move temporary cert zip file on Ansible controler
140140
ansible.builtin.copy:
141-
src: /tmp/{{ ansible_hostname }}-ls.zip
142-
dest: "/tmp/{{ ansible_hostname }}-ls.zip_{{ ansible_date_time.iso8601_micro }}"
141+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip"
142+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip_{{ ansible_date_time.iso8601_micro }}"
143143
mode: preserve
144144
when: logstash_check_temporary_cert_zip_ansible_controler.stat.exists
145145
register: logstash_move_cert_zip_ansible_controler
146146

147147
- name: Remove temporary cert zip file on Ansible controler
148148
ansible.builtin.file:
149-
path: /tmp/{{ ansible_hostname }}-ls.zip
149+
path: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip"
150150
state: absent
151151
when: logstash_move_cert_zip_ansible_controler.changed
152152

@@ -173,7 +173,7 @@
173173
- name: Fetch certificate from ca host to Ansible controler
174174
ansible.builtin.fetch:
175175
src: "{{ elasticstack_ca_dir }}/{{ ansible_hostname }}-ls.p12"
176-
dest: "/tmp/{{ ansible_hostname }}-ls.p12"
176+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
177177
flat: yes
178178
delegate_to: "{{ elasticstack_ca }}"
179179
tags:
@@ -195,7 +195,7 @@
195195

196196
- name: Copy the certificate to logstash node
197197
ansible.builtin.copy:
198-
src: "/tmp/{{ ansible_hostname }}-ls.p12"
198+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
199199
dest: "{{ logstash_certs_dir }}/{{ ansible_hostname }}-ls.p12"
200200
owner: root
201201
group: logstash
@@ -207,7 +207,7 @@
207207

208208
- name: Put the certificate in keystore
209209
ansible.builtin.copy:
210-
src: "/tmp/{{ ansible_hostname }}-ls.p12"
210+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.p12"
211211
dest: "{{ logstash_certs_dir }}/keystore.pfx"
212212
owner: root
213213
group: logstash
@@ -243,7 +243,7 @@
243243
- name: Fetch PEM certificate from ca host to Ansible controler
244244
ansible.builtin.fetch:
245245
src: "{{ elasticstack_ca_dir }}/{{ ansible_hostname }}-ls.zip"
246-
dest: "/tmp/{{ ansible_hostname }}-ls.zip"
246+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip"
247247
flat: yes
248248
delegate_to: "{{ elasticstack_ca }}"
249249
tags:
@@ -253,7 +253,7 @@
253253

254254
- name: Copy PEM certificate to logstash node
255255
ansible.builtin.unarchive:
256-
src: "/tmp/{{ ansible_hostname }}-ls.zip"
256+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/{{ ansible_hostname }}-ls.zip"
257257
dest: "{{ logstash_certs_dir }}/"
258258
owner: root
259259
group: logstash
@@ -323,7 +323,7 @@
323323
- name: Fetch ca certificate from ca host to Ansible controler
324324
ansible.builtin.fetch:
325325
src: "{{ elasticstack_ca_dir }}/ca.crt"
326-
dest: /tmp/ca.crt
326+
dest: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
327327
flat: yes
328328
delegate_to: "{{ elasticstack_ca }}"
329329
tags:
@@ -333,7 +333,7 @@
333333

334334
- name: Copy the ca certificate to logstash node
335335
ansible.builtin.copy:
336-
src: /tmp/ca.crt
336+
src: "{{ lookup('config', 'DEFAULT_LOCAL_TMP') | dirname }}/ca.crt"
337337
dest: "{{ logstash_certs_dir }}"
338338
owner: root
339339
group: logstash

0 commit comments

Comments
 (0)