Skip to content

Commit 96f4ddc

Browse files
committed
Put existing ohpc secrets on persistent storage
1 parent 5d92993 commit 96f4ddc

File tree

1 file changed

+37
-16
lines changed
  • roles/persist_openhpc_secrets/tasks

1 file changed

+37
-16
lines changed
Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
---
22

3-
- name: Check if OpenHPC secrets exist
3+
- name: Ensure Ansible facts directory exists
4+
file:
5+
path: "{{ appliances_state_dir }}/ansible.facts.d"
6+
state: directory
7+
owner: root
8+
mode: 0600
9+
10+
- name: Check if OpenHPC secrets exist in persistent state dir
11+
stat:
12+
path: "{{ appliances_state_dir }}/ansible.facts.d/openhpc_secrets.fact"
13+
register: openhpc_secrets
14+
15+
- name: Check if an OpenHPC facts file exists in /etc/ansible/facts.d
416
stat:
5-
path: "{{ appliances_state_dir }}/ansible/facts.d/openhpc_secrets.fact"
6-
register: openhpc_secrets_stat
17+
path: "/etc/ansible/facts.d/openhpc_secrets.fact"
18+
register: existing_openhpc_secrets
719

8-
- name: Persist OpenHPC secrets
20+
- name: Create or move OpenHPC secrets to persistent state volume
921
block:
10-
- name: Ensure Ansible facts directory exists
11-
file:
12-
path: "{{ appliances_state_dir }}/ansible/facts.d"
13-
state: directory
14-
owner: root
15-
mode: 0600
16-
recurse: yes
17-
18-
- name: Write OpenHPC secrets
22+
- name: Move OpenHPC secrets to persistent state volume if they already exist in /etc/ansible/facts.d
23+
block:
24+
- name: Copy existing OpenHPC facts file to persistent storage
25+
copy:
26+
remote_src: true
27+
src: "/etc/ansible/facts.d/openhpc_secrets.fact"
28+
dest: "{{ appliances_state_dir }}/ansible.facts.d/openhpc_secrets.fact"
29+
mode: 0600
30+
owner: root
31+
32+
- name: Remove existing OpenHPC secrets file from /etc/ansible/facts.d
33+
file:
34+
state: absent
35+
path: "/etc/ansible/facts.d/openhpc_secrets.fact"
36+
when: existing_openhpc_secrets.stat.exists
37+
38+
- name: Write new OpenHPC secrets
1939
template:
2040
src: openhpc_secrets.fact
2141
dest: "{{ appliances_state_dir }}/ansible/facts.d/openhpc_secrets.fact"
2242
owner: root
2343
mode: 0600
24-
when: "not openhpc_secrets_stat.stat.exists"
44+
when: "not existing_openhpc_secrets.stat.exists"
45+
when: "not openhpc_secrets.stat.exists"
2546

26-
- name: Read facts
47+
- name: Read OpenHPC secrets
2748
ansible.builtin.setup:
28-
fact_path: "{{ appliances_state_dir }}/ansible/facts.d"
49+
fact_path: "{{ appliances_state_dir }}/ansible.facts.d"
2950
filter: ansible_local

0 commit comments

Comments
 (0)