11---
22
3+ # STATUS:
4+
5+ # looks like it works for caas, but not for normal now
6+
7+ # can't use ansible.builtin.include_vars - that only looks on the deploy host
8+ # (even with delegate)
9+
10+ # For caas where passwords_output_path isn't actually in inventory we need
11+ # to load them first, so that templating is idempotent
12+
13+ - name : Slurp passwords if defined
14+ ansible.builtin.slurp :
15+ src : " {{ passwords_output_path }}"
16+ delegate_to : " {{ passwords_host }}"
17+ register : _passwords_slurp_first
18+ failed_when :
19+ - _passwords_slurp_first.failed
20+ - " 'file not found' not in _passwords_slurp_first.msg"
21+
22+ - name : Set facts for passwords
23+ set_fact :
24+ " {{ item.key }} " : " {{ item.value }}"
25+ when : " 'content' in _passwords_slurp_first"
26+ loop : " {{ _passwords_slurp_first.content | b64decode | from_yaml | dict2items }}"
27+ no_log : " {{ no_log | default(true) }}"
28+
29+ # - name: Set facts for passwords
30+ # set_fact:
31+ # # nah can't template yaml keys so not sure we can do this!
32+ # when: not _passwords_slurp.failed
33+ # loop: "{{ _passwords_slurp.content | b64decode | from_yaml }}"
34+
35+ - name : Ensure secrets directory exists
36+ file :
37+ path : " {{ passwords_output_path | dirname }}"
38+ owner : " {{ passwords_owner }}"
39+ group : " {{ passwords_group }}"
40+ state : directory
41+ # mode: ug=rwX,o=rX # non-caas for caas we want u=rwx,go=
42+ delegate_to : " {{ passwords_host }}"
43+ become : " {{ passwords_owner != ansible_user }}" # not sure about this in the general case but seems ok here
44+ run_once : true
45+
346- name : Template passwords
447 template :
548 src : passwords.yml
6- dest : " {{ openhpc_passwords_output_path }}"
7- delegate_to : localhost
49+ dest : " {{ passwords_output_path }}"
50+ owner : " {{ passwords_owner }}"
51+ group : " {{ passwords_group }}"
52+ become : " {{ passwords_owner != ansible_user }}"
53+ delegate_to : " {{ passwords_host }}"
854 run_once : true
55+ register : _passwords_template
56+
57+ # even if the files are in inventory, even meta: inventory_reload doesn't
58+ # get the new variables, so we need to set them as facts:
59+ - name : Slurp passwords if changed
60+ ansible.builtin.slurp :
61+ src : " {{ passwords_output_path }}"
62+ delegate_to : " {{ passwords_host }}"
63+ register : _passwords_slurp_second
64+ when : _passwords_template.changed
65+
66+ - name : Set facts for passwords
67+ set_fact :
68+ " {{ item.key }} " : " {{ item.value }}"
69+ when : not _passwords_slurp_second.skipped | default(false)
70+ loop : " {{ _passwords_slurp_second.content | b64decode | from_yaml | dict2items }}"
71+ no_log : " {{ no_log | default(true) }}"
72+
73+
74+ # we do see passwords end up in the templated config for slurm-controlled rebuild!
75+
76+
77+ # oh man maybe this doesn't work b/c things are accessed through hostvars[*] ...
78+
79+ # also; does this work for caas?? Because the vars won't be in inventory to
80+ # start with, so then they won't exist, so they'll be re-templated despite
81+ # the fact the file exists. Maybe we need to load them first, if the file
82+ # exists??
0 commit comments