6d23d20f2f
This is preparation for a later version of ansbile-lint, which finds missing names on blocks. This seems a reasonable rule, and the Ansible manual says [1] Names for blocks have been available since Ansible 2.3. We recommend using names in all tasks, within blocks or elsewhere, for better visibility into the tasks being executed when you run the playbook. This simply adds a name tag for blocks that are missing it. This should have no operational change, but allows us to update the linter in a follow-on change. [1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html Change-Id: I92ed4616775650aced352bc9088a07e919f1a25f
36 lines
1.2 KiB
YAML
36 lines
1.2 KiB
YAML
---
|
|
# Use a block to add become to a set of tasks
|
|
- name: Add build ssh key
|
|
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 {{ copy_sshkey_target_user }} user home folder
|
|
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
|
|
become: true
|