# Template unable to replace file; the playbook uses "become" to get the elevated permission

**URL:** <https://forum.ansible.com/t/template-unable-to-replace-file-the-playbook-uses-become-to-get-the-elevated-permission/20260>\
**Category:** Ansible Project\
**Created:** [January 19, 2016, 3:16am UTC](https://forum.ansible.com/t/template-unable-to-replace-file-the-playbook-uses-become-to-get-the-elevated-permission/20260 "2016-01-19T03:16:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indra\_Gunawan](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Indra\_Gunawan](https://forum.ansible.com/u/Indra_Gunawan)\
**Post date:** [January 19, 2016, 3:16am UTC](https://forum.ansible.com/t/template-unable-to-replace-file-the-playbook-uses-become-to-get-the-elevated-permission/20260/1 "2016-01-19T03:16:06Z")

</div>

This error is a blocker my effort to use Template to automate our Jenkins installation to target Jenkins master on our corporate environment:

PUT /tmp/tmpUjjIrF TO /users/ingunawa/.ansible/tmp/ansible-tmp-1453075333.7-198301965511122/source  
EXEC ( umask 22 && mkdir -p “$( echo $HOME/.ansible/tmp/ansible-tmp-1453075334.26-42896703240882 )” && echo “$( echo $HOME/.ansible/tmp/ansible-tmp-1453075334.26-42896703240882 )” )  
PUT /tmp/tmpcz5OYl TO /users/ingunawa/.ansible/tmp/ansible-tmp-1453075334.26-42896703240882/copy  
EXEC /bin/sh -c ‘sudo -H -S -p “[sudo via ansible, key=vtgcupyzjtojsbtboeyttvmiwyunzkwc] password: " -u root /bin/sh -c '”’“‘echo BECOME-SUCCESS-vtgcupyzjtojsbtboeyttvmiwyunzkwc; LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /users/ingunawa/.ansible/tmp/ansible-tmp-1453075334.26-42896703240882/copy; rm -rf “/users/ingunawa/.ansible/tmp/ansible-tmp-1453075334.26-42896703240882/” \> /dev/null 2\>&1’”‘"’’  
fatal: [sjc-nmtgci-15]: FAILED! =\> {“changed”: true, “failed”: true, “invocation”: {“module\_args”: {“dest”: “/opt/nmtgre-tools/jenkins/config/jenkins”, “group”: “eng”, “mode”: “0600”, “owner”: “px-build”, “src”: “default-jenkins.j2”}, “module\_name”: “template”}, “module\_stderr”: “”, “module\_stdout”: “\r\nBECOME-SUCCESS-vtgcupyzjtojsbtboeyttvmiwyunzkwc\r\n{"msg": "Could not replace file: /users/ingunawa/.ansible/tmp/ansible-tmp-1453075333.7-198301965511122/source to /opt/nmtgre-tools/jenkins/config/jenkins: [Errno 13] Permission denied: ‘/users/ingunawa/.ansible/tmp/ansible-tmp-1453075333.7-198301965511122/source’", "failed": true, "invocation": {"module\_args": {"src": "/users/ingunawa/.ansible/tmp/ansible-tmp-1453075333.7-198301965511122/source", "directory\_mode": null, "force": true, "follow": true, "remote\_src": null, "dest": "/opt/nmtgre-tools/jenkins/config/jenkins", "selevel": null, "seuser": null, "serole": null, "content": null, "setype": null, "original\_basename": "default-jenkins.j2", "delimiter": null, "mode": "0600", "regexp": null, "owner": "px-build", "group": "eng", "validate": null, "backup": false}}}\r\nException exceptions.OSError: (2, ‘No such file or directory’, ‘/opt/nmtgre-tools/jenkins/config/.ansible\_tmpFDjmX5jenkins’) in ', mode ‘w+b’ at 0x16019a80\>\> ignored\r\n”, “msg”: “MODULE FAILURE”, “parsed”: false}

Here is the playbook (roles/jenkins-master/tasks/main.yml)

---

<div class="post-metadata">

**Author:** ![Indra\_Gunawan](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Indra\_Gunawan](https://forum.ansible.com/u/Indra_Gunawan)\
**Post date:** [January 19, 2016, 9:19pm UTC](https://forum.ansible.com/t/template-unable-to-replace-file-the-playbook-uses-become-to-get-the-elevated-permission/20260/2 "2016-01-19T21:19:07Z")

</div>

> I am running it as me (userid: ingunawa) like this “ansible-playbook -i hosts jenkins-master.xml --limit -k -K”

I have sudo permission on the target machine/VM. I can create/copy file to /etc/init.d as root and create/copy file to the other directory owned by the other user (generic user) owning/running Jenkins.

May I know how Template is used ideally with “become”. The become\_method by default is “sudo”.  
The default “become\_user” is root I believe.

Thank you
