|
126 | 126 | format: zip |
127 | 127 | remove: no |
128 | 128 |
|
129 | | -- name: Get SSH configuration for the kdevops archive repo |
130 | | - ansible.builtin.command: ssh -G {{ kdevops_results_repo_url_user }}@{{ kdevops_results_repo_path }} |
131 | | - register: ssh_archive_config_repo |
132 | | - changed_when: false |
133 | | - |
134 | | -- name: Extract kdevops archive repo IdentityFile |
135 | | - vars: |
136 | | - identity_file_lines: "{{ ssh_archive_config_repo.stdout_lines | select('match', '^identityfile ') }}" |
137 | | - identity_file_raw: "{{ identity_file_lines | first | regex_replace('^identityfile (.*)$', '\\1') }}" |
138 | | - ansible.builtin.set_fact: |
139 | | - kdevops_archive_identity_file: "{{ identity_file_raw | regex_replace('^~', lookup('env', 'HOME')) }}" |
140 | | - |
141 | | -- name: Check if the key used for the kdevops archive repo is installed |
142 | | - ansible.builtin.set_fact: |
143 | | - kdevops_archive_key_detected: "{{ kdevops_archive_key_name in (kdevops_archive_identity_file | basename) }}" |
144 | | - |
145 | | -- name: Inform user of how to set up the kdevops archive repo key |
146 | | - ansible.builtin.debug: |
147 | | - msg: | |
148 | | - ssh key archive test for {{ kdevops_results_repo_url }}: |
149 | | - We ran: |
150 | | -
|
151 | | - ssh -G {{ kdevops_results_repo_url_user }}@{{ kdevops_results_repo_path }} | grep identityfile |
152 | | -
|
153 | | - Missing key name: '{{ kdevops_archive_key_name }}' |
154 | | - Current IdentityFile: |
155 | | - {{ kdevops_archive_identity_file }} |
156 | | -
|
157 | | - To set up automatic kdevops repo archiving install something like |
158 | | - the following key for host {{ kdevops_archive_host }}: |
159 | | -
|
160 | | - Host {{ kdevops_results_repo_path }} |
161 | | - User {{ kdevops_results_repo_url_user }} |
162 | | - Hostname {{ kdevops_archive_host }} |
163 | | - IdentityFile {{ lookup('env', 'HOME') }}/.ssh/{{ kdevops_archive_key_name }} |
164 | | -
|
165 | | -
|
166 | | - Create the key first with something like: |
167 | | -
|
168 | | - ssh-keygen -t ed25519 -C "{{ kdevops_results_repo_url_user}}@{{ kdevops_results_repo_path }}" -f {{ lookup('env', 'HOME') }}/.ssh/{{ kdevops_archive_key_name }} |
169 | | -
|
170 | | - Then install it as deploy key for {{ kdevops_results_repo_path}}: |
171 | | -
|
172 | | - https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#deploy-keys |
173 | | -
|
174 | | - And then add the above to your {{ lookup('env', 'HOME') }}/.ssh/config |
175 | | -
|
176 | | - when: |
177 | | - - 'not kdevops_archive_key_detected|bool' |
178 | | - - 'bootlinux_tree_set_by_cli|bool' |
179 | | - |
180 | | -- name: Gracefully end if key is not found for automatic kdevops archiving |
181 | | - meta: end_play |
182 | | - when: |
183 | | - - not kdevops_archive_key_detected |
184 | | - |
185 | | -- name: Check if the detected kdevops archive repo key exists |
186 | | - ansible.builtin.stat: |
187 | | - path: "{{ kdevops_archive_identity_file }}" |
188 | | - register: ssh_key_file_lookup |
189 | | - |
190 | | -- name: Inform user of configured but not created key |
191 | | - ansible.builtin.debug: |
192 | | - msg: | |
193 | | - Key to be used missing: {{ kdevops_archive_identity_file }} |
194 | | - Create the key with something like: |
195 | | - ssh-keygen -t ed25519 -C "{{ kdevops_results_repo_url_user}}@{{ kdevops_results_repo_path }}" -f {{ lookup('env', 'HOME') }}/.ssh/{{ kdevops_archive_key_name }} |
196 | | - when: |
197 | | - - not ssh_key_file_lookup.stat.exists |
198 | | - |
199 | | -- name: Gracefully end if key does not exist |
200 | | - meta: end_play |
201 | | - when: |
202 | | - - not ssh_key_file_lookup.stat.exists |
203 | | - |
204 | | -- name: Check if kdevops results archive ssh key has a passphrase |
205 | | - ansible.builtin.command: |
206 | | - cmd: "ssh-keygen -y -f {{ kdevops_archive_identity_file }}" |
207 | | - register: ssh_key_check |
208 | | - ignore_errors: yes |
209 | | - changed_when: false |
210 | | - failed_when: false |
211 | | - no_log: true |
212 | | - |
213 | | -- name: Set fact about SSH key passphrase status |
214 | | - ansible.builtin.set_fact: |
215 | | - kdevops_archive_key_has_passphrase: "{{ ssh_key_check.rc != 0 }}" |
216 | | - |
217 | | -- name: Inform user if key did not have a passphrase |
218 | | - ansible.builtin.debug: |
219 | | - msg: | |
220 | | - ssh key archive {{ kdevops_archive_identity_file }} for {{ kdevops_results_repo_url }} |
221 | | - does not have a passphrase. This not secure and not allowed. Giving up. |
222 | | - when: |
223 | | - - 'not kdevops_archive_key_has_passphrase|bool' |
224 | | - |
225 | | -- name: End if key did not have passphrase set up |
226 | | - meta: end_play |
227 | | - when: |
228 | | - - 'not kdevops_archive_key_has_passphrase|bool' |
229 | | - |
230 | | -- name: Gracefully end if the user did not set up a kdevops archive repo key |
231 | | - meta: end_play |
232 | | - when: not kdevops_archive_key_detected |
233 | | - |
234 | | -- name: Get fingerprint of the identity file for {{ kdevops_archive_key_name }} |
235 | | - ansible.builtin.command: ssh-keygen -lf "{{ kdevops_archive_identity_file }}" |
236 | | - register: kdevops_archive_fingerprint_output |
237 | | - changed_when: false |
238 | | - when: |
239 | | - - 'kdevops_archive_key_detected|bool' |
240 | | - |
241 | | -- name: Extract the {{ kdevops_archive_key_name }} fingerprint |
242 | | - ansible.builtin.set_fact: |
243 | | - kdevops_archive_key_fingerprint: "{{ kdevops_archive_fingerprint_output.stdout.split()[1] }}" |
244 | | - when: |
245 | | - - 'kdevops_archive_key_detected|bool' |
246 | | - |
247 | | -- name: List keys in ssh-agent |
248 | | - ansible.builtin.command: ssh-add -l |
249 | | - register: kdevops_archive_ssh_add_list |
250 | | - changed_when: false |
251 | | - when: |
252 | | - - 'kdevops_archive_key_detected|bool' |
253 | | - |
254 | | -- name: Check if key is loaded in ssh-agent |
255 | | - ansible.builtin.set_fact: |
256 | | - kdevops_archive_key_loaded: "{{ kdevops_archive_key_fingerprint in kdevops_archive_ssh_add_list.stdout }}" |
257 | | - |
258 | | -- name: Inform when we are achiving |
259 | | - ansible.builtin.debug: |
260 | | - msg: "Achievement unlocked: kdevops archive key set up, automatic kdevops archiving enabled." |
261 | | - when: |
262 | | - - 'kdevops_archive_key_loaded|bool' |
263 | | - |
264 | 129 | - name: Check if kdevops-results-archive directory exists |
265 | 130 | stat: |
266 | 131 | path: "{{ kdevops_results_archive_dir }}" |
|
0 commit comments