-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/compute-init-cookiecutter
- Loading branch information
Showing
7 changed files
with
48 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
# persist_hostkeys | ||
|
||
Save hostkeys to persistent storage and restore them after a rebuild/reimage. | ||
Idempotently generates a persistent set of hostkeys and restores them after a rebuild/reimage. | ||
|
||
Add hosts to the `persist_hostkeys` group to enable. | ||
|
||
This role has no variables but hosts in this group must have `appliances_state_dir` | ||
defined as a directory they can write to on persistent storage. | ||
Add hosts to the `persist_hostkeys` group to enable. All hosts in group will share the same set hostkeys. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
persist_hostkeys_state_server: "{{ groups['control'] | first }}" | ||
persist_hostkeys_state_dir: "{{ hostvars[persist_hostkeys_state_server]['appliances_state_dir'] }}/hostkeys" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
--- | ||
|
||
- name: Ensure hostkeys directory exists on persistent storage | ||
file: | ||
path: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0600 | ||
- name: Generate persistent hostkeys in state directory | ||
delegate_to: "{{ persist_hostkeys_state_server }}" | ||
block: | ||
- name: Ensure hostkeys directory exists on persistent storage | ||
file: | ||
path: "{{ persist_hostkeys_state_dir }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0600 | ||
|
||
- name: Copy hostkeys from persistent storage | ||
# won't fail if no keys are in persistent storage | ||
copy: | ||
src: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/" | ||
dest: /etc/ssh/ | ||
remote_src: true | ||
- name: Check for existing hostkeys | ||
find: | ||
paths: "{{ persist_hostkeys_state_dir }}/" | ||
register: _files_found | ||
|
||
- name: Generate hostkeys | ||
when: _files_found.matched == 0 | ||
shell: | ||
# ssh-keygen -A needs a directory with an /etc/ssh suffix to write hostkeys into | ||
cmd: | | ||
mkdir -p {{ persist_hostkeys_state_dir }}/etc/ssh | ||
ssh-keygen -A -N '' -f {{ persist_hostkeys_state_dir }} | ||
mv {{ persist_hostkeys_state_dir }}/etc/ssh/* {{ persist_hostkeys_state_dir }} | ||
rm -rf {{ persist_hostkeys_state_dir }}/etc/ssh | ||
- name: Get created key names | ||
find: | ||
path: "{{ persist_hostkeys_state_dir }}/" | ||
register: _find_ssh_keys | ||
|
||
- name: Find hostkeys | ||
find: | ||
path: /etc/ssh/ | ||
patterns: ssh_host_*_key* | ||
register: _find_ssh_keys | ||
- name: Create in-memory copies of keys | ||
ansible.builtin.slurp: | ||
src: "{{ item.path }}" | ||
loop: "{{ _find_ssh_keys.files }}" | ||
register: _slurp_keys | ||
|
||
- name: Persist hostkeys | ||
- name: Copy keys to hosts | ||
no_log: true | ||
copy: | ||
dest: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/" | ||
src: "{{ item }}" | ||
remote_src: true | ||
mode: preserve | ||
loop: "{{ _find_ssh_keys.files | map(attribute='path') }}" | ||
content: "{{ item.content | b64decode }}" | ||
dest: "/etc/ssh/{{ item.source | regex_search('[^/]+$') }}" | ||
loop: "{{ _slurp_keys.results }}" | ||
|
||
- meta: reset_connection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,3 @@ compute | |
|
||
[podman:children] | ||
zenith | ||
|
||
[persist_hostkeys:children] | ||
openondemand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters