From e79be26f70c0235762b19cc2f08149519ed81dd7 Mon Sep 17 00:00:00 2001
From: "Andrea Frittoli (andreaf)" <andrea.frittoli@gmail.com>
Date: Tue, 24 Apr 2018 11:57:43 +0100
Subject: [PATCH] Run authorized_keys as root

Using become_user only works if either the ansible_user is root
or pipeling is enabled. Use become instead to avoid the dependency
on pipelining being enabled.

Change-Id: I2ca65ab38b51d4949295674abfe594ce26fe35a1
---
 roles/copy-build-sshkey/tasks/main.yaml | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/roles/copy-build-sshkey/tasks/main.yaml b/roles/copy-build-sshkey/tasks/main.yaml
index 49a26dc59..496347bb2 100644
--- a/roles/copy-build-sshkey/tasks/main.yaml
+++ b/roles/copy-build-sshkey/tasks/main.yaml
@@ -1,15 +1,13 @@
 ---
-# 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') }}"
-  become: true
-  become_user: "{{ copy_sshkey_target_user }}"
-
 # Use a block to add become to a set of tasks
 - 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 }}"