# template module ignoring become\_user?

**URL:** <https://forum.ansible.com/t/template-module-ignoring-become-user/19236>\
**Category:** Ansible Project\
**Created:** [September 11, 2015, 10:14am UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236 "2015-09-11T10:14:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [September 11, 2015, 10:14am UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/1 "2015-09-11T10:14:34Z")

</div>

Hi!

I’m trying to run a playbook locally and also trying to use the template module here.

This is an excerpt from my playbook:

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 11, 2015, 2:02pm UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/2 "2015-09-11T14:02:07Z")

</div>

Modules don't know anything about become, it gets handled by ansible  
itself and not the module. We seem to be missing some output as the  
last command makes the temp dirs and then you get the error on  
permission denied w/o the command that we attempted to execute.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 11, 2015, 2:02pm UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/3 "2015-09-11T14:02:09Z")

</div>

Modules don't know anything about become, it gets handled by ansible  
itself and not the module. We seem to be missing some output as the  
last command makes the temp dirs and then you get the error on  
permission denied w/o the command that we attempted to execute.

---

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [September 14, 2015, 5:48am UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/4 "2015-09-14T05:48:22Z")

</div>

Thanks for answering, Brian.

No, there is no output missing as I reduced the testcase to the bare minimum.

But I think I know where the problem is. Let me explain:

I’m setting this all up in a cloud-like environment where the user I have to use on the target system is not root, but may sudo to root.

What I wanted to achieve is to update the content of a webserver, by regularly polling a subversion repository.

What happens when the playbook was updated is:  
a) User vfuser (my crontab user) is starting ansible-playbook  
b) the playbook has a become-user: apache and updates its content using subversion  
c) some templates now need to be updated which need be done by user apache, as the working copy belongs to apache → This fails as ansible tries to do this as vfuser

Of course ansible has to do this as vfuser (the one running ansible) as this would be the only valid user in a push-scenario.

Unfortunately I’m in a pull-scenario and so vfuser does not have permission.

I’m doing it now (overly complicated?) like this:

- Update Content
- This is the svn up. getting the content for apache
- Make Templates Accessible
- Does a chmod 0755 on all the updated directories
- Remove Dummy Dargets
- Removes all the html files, which will get created, just in case they already exist
- Create Dummy Targets
- Now create the empty html files and chown them to vfuser
- Fill Templates
- Fill the templates as vfuser
- Set Permission of Targets
- chown back to apache
- Cleanup Templates
- remove the templates

I’m not sure whether or not I found an “edge-case”, but I think it could be beneficial, could the template-fill also be run under “become\_user”.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 14, 2015, 3:18pm UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/5 "2015-09-14T15:18:14Z")

</div>

The template get's 'filled' on the master so the remote/become users  
do not matter at that point, the filled template gets copied to the  
target machine as the remote user, which in the case of sudo to non  
root user it will go to a more permissive directory (the case is  
already handled).

For some reason your task seems to be skipping that step and then not  
running the command to copy into place, which should show with -vvvv  
but it is not being shown for whatever reason (probably related to why  
you are getting an error).

---

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [September 15, 2015, 5:31am UTC](https://forum.ansible.com/t/template-module-ignoring-become-user/19236/6 "2015-09-15T05:31:20Z")

</div>

> The template get’s ‘filled’ on the master so the remote/become users  
> do not matter at that point,

It could (and here does) matter when you run locally because master and target are the same machine.

> For some reason your task seems to be skipping that step and then not  
> running the command to copy into place,

It skips that step because the filling does not work.
