|
1 | 1 | ---
|
| 2 | + |
2 | 3 | - name: Generate persistent hostkeys in state directory
|
3 | 4 | delegate_to: "{{ persist_hostkeys_state_server }}"
|
4 | 5 | block:
|
5 |
| - - name: Ensure hostkeys directory exists on persistent storage |
6 |
| - ansible.builtin.file: |
7 |
| - path: "{{ persist_hostkeys_state_dir }}" |
8 |
| - state: directory |
9 |
| - owner: root |
10 |
| - group: root |
11 |
| - mode: "0600" |
12 |
| - |
13 |
| - - name: Check for existing hostkeys |
14 |
| - ansible.builtin.find: |
15 |
| - paths: "{{ persist_hostkeys_state_dir }}/" |
16 |
| - register: _files_found |
| 6 | + - name: Ensure hostkeys directory exists on persistent storage |
| 7 | + file: |
| 8 | + path: "{{ persist_hostkeys_state_dir }}" |
| 9 | + state: directory |
| 10 | + owner: root |
| 11 | + group: root |
| 12 | + mode: 0600 |
17 | 13 |
|
18 |
| - - name: Generate hostkeys # noqa: no-changed-when |
19 |
| - when: _files_found.matched == 0 |
20 |
| - ansible.builtin.shell: |
21 |
| - # ssh-keygen -A needs a directory with an /etc/ssh suffix to write hostkeys into |
22 |
| - cmd: | |
23 |
| - mkdir -p {{ persist_hostkeys_state_dir }}/etc/ssh |
24 |
| - ssh-keygen -A -N '' -f {{ persist_hostkeys_state_dir }} |
25 |
| - mv {{ persist_hostkeys_state_dir }}/etc/ssh/* {{ persist_hostkeys_state_dir }} |
26 |
| - rm -rf {{ persist_hostkeys_state_dir }}/etc/ssh |
| 14 | + - name: Check for existing hostkeys |
| 15 | + find: |
| 16 | + paths: "{{ persist_hostkeys_state_dir }}/" |
| 17 | + register: _files_found |
27 | 18 |
|
28 |
| - - name: Get created key names |
29 |
| - ansible.builtin.find: |
30 |
| - path: "{{ persist_hostkeys_state_dir }}/" |
31 |
| - register: _find_ssh_keys |
| 19 | + - name: Generate hostkeys |
| 20 | + when: _files_found.matched == 0 |
| 21 | + shell: |
| 22 | + # ssh-keygen -A needs a directory with an /etc/ssh suffix to write hostkeys into |
| 23 | + cmd: | |
| 24 | + mkdir -p {{ persist_hostkeys_state_dir }}/etc/ssh |
| 25 | + ssh-keygen -A -N '' -f {{ persist_hostkeys_state_dir }} |
| 26 | + mv {{ persist_hostkeys_state_dir }}/etc/ssh/* {{ persist_hostkeys_state_dir }} |
| 27 | + rm -rf {{ persist_hostkeys_state_dir }}/etc/ssh |
| 28 | + |
| 29 | + - name: Get created key names |
| 30 | + find: |
| 31 | + path: "{{ persist_hostkeys_state_dir }}/" |
| 32 | + register: _find_ssh_keys |
32 | 33 |
|
33 |
| - - name: Create in-memory copies of keys |
34 |
| - ansible.builtin.slurp: |
35 |
| - src: "{{ item.path }}" |
36 |
| - loop: "{{ _find_ssh_keys.files }}" |
37 |
| - register: _slurp_keys |
| 34 | + - name: Create in-memory copies of keys |
| 35 | + ansible.builtin.slurp: |
| 36 | + src: "{{ item.path }}" |
| 37 | + loop: "{{ _find_ssh_keys.files }}" |
| 38 | + register: _slurp_keys |
38 | 39 |
|
39 | 40 | - name: Copy keys to hosts
|
40 | 41 | no_log: true
|
41 |
| - ansible.builtin.copy: |
| 42 | + copy: |
42 | 43 | content: "{{ item.content | b64decode }}"
|
43 | 44 | dest: "/etc/ssh/{{ item.source | regex_search('[^/]+$') }}"
|
44 |
| - mode: "0644" |
45 | 45 | loop: "{{ _slurp_keys.results }}"
|
46 | 46 |
|
47 |
| -- ansible.builtin.meta: reset_connection |
| 47 | +- meta: reset_connection |
0 commit comments