zuul-jobs/roles/copy-build-sshkey/tasks/main.yaml
Ian Wienand 8c6512107c
Standarise block/when ordering
Newer ansbile-lint finds "when" or "become" statements that are at the
end of blocks.  Ordering these before the block seems like a very
logical thing to do, as we read from top-to-bottom so it's good to see
if the block will execute or not.

This is a no-op, and just moves the places the newer linter found.

Change-Id: If4d1dc4343ea2575c64510e1829c3fe02d6c273f
2022-11-07 10:37:53 +11:00

36 lines
1.2 KiB
YAML

---
# Use a block to add become to a set of tasks
- name: Add build ssh key
become: true
block:
# Add the authorization first, to take advantage of manage_dir
- name: Authorize build key
authorized_key:
user: "{{ copy_sshkey_target_user }}"
manage_dir: yes
key: "{{ lookup('file', zuul_temp_ssh_key ~ '.pub') }}"
- name: 'Get the user home folder for {{ copy_sshkey_target_user }}'
user:
name: "{{ copy_sshkey_target_user }}"
register: target_user_registered
# The copy module does not work with become_user even if pipelining is
# enabled when both ansible user and become_user are not root:
# http://docs.ansible.com/ansible/latest/user_guide/become.html#becoming-an-unprivileged-user
- name: Install the build private key
copy:
src: "{{ zuul_temp_ssh_key }}"
dest: "{{ target_user_registered.home }}/.ssh/id_rsa"
mode: 0600
owner: "{{ copy_sshkey_target_user }}"
force: no
- name: Install the build public key
copy:
src: "{{ zuul_temp_ssh_key }}.pub"
dest: "{{ target_user_registered.home }}/.ssh/id_rsa.pub"
mode: 0644
owner: "{{ copy_sshkey_target_user }}"
force: no