# Problem change user with become or become\_user

**URL:** <https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866>\
**Category:** Ansible Project\
**Created:** [July 25, 2019, 12:50pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866 "2019-07-25T12:50:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [July 25, 2019, 12:50pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866/1 "2019-07-25T12:50:20Z")

</div>

Hey,

Hello every body !!

I work on Ansible and i have problem, when i want use **become: yes** or **become\_user: root** it’s not works.

My task is :

- name: “Create directory”  
file:  
path: /var/apps  
state: directory  
**become\_user: root**

But when i use this task just before :

- set\_fact:  
ansible\_user: root

My directory is create with success !! WHY ?

Someone have any idea please community ansible ??? I’m desperte ☹

Thank you very much !!

Regards,

Karther

---

<div class="post-metadata">

**Author:** ![Mark\_Anthony\_Garcia](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@Mark\_Anthony\_Garcia](https://forum.ansible.com/u/Mark_Anthony_Garcia)\
**Post date:** [July 25, 2019, 1:25pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866/2 "2019-07-25T13:25:28Z")

</div>

Hi Karther,

I’m not an expert in ansible but with my current experience I believe this works for you because you are logging in as root which is the owner of /var/ folder. ansible\_user is a default variable.

Typically for other modules like lineinfile I add ansible\_beome: yes, which means run the file as sudo. my ansible\_beocme\_password is defined as a variable so I guess you can try doing that.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 25, 2019, 1:28pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866/3 "2019-07-25T13:28:45Z")

</div>

> Hey,
> 
> Hello every body !!
> 
> I work on Ansible and i have problem, when i want use become: yes or become\_user: root it's not works.
> 
> My task is :
> 
> - name: "Create directory"  
> &nbsp;&nbsp;file:  
> &nbsp;&nbsp;&nbsp;&nbsp;path: /var/apps  
> &nbsp;&nbsp;&nbsp;&nbsp;state: directory  
> &nbsp;&nbsp;become\_user: root

become\_user only tells ansible what user to become - not that it use  
privilege escalation.  
Also, become\_user is default 'root', so that directive is redundant.

Instead simply use:

become: yes

> But when i use this task just before :
> 
> - set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible\_user: root
> 
> My directory is create with success !! WHY ?

This means that ansible will sign in to the server as root, so then no  
permission issues.

---

<div class="post-metadata">

**Author:** ![P.Cookson](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@P.Cookson](https://forum.ansible.com/u/P.Cookson)\
**Post date:** [July 25, 2019, 2:09pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866/4 "2019-07-25T14:09:14Z")

</div>

If your system allows you to go straight in as root, you could possibly use “remote\_user” before running the task (see below):

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [July 25, 2019, 3:37pm UTC](https://forum.ansible.com/t/problem-change-user-with-become-or-become-user/30866/5 "2019-07-25T15:37:56Z")

</div>

Hey,

Thanks very much community Ansible !!

The solution is to use **remote\_user: root** for that ansible execut this task in root !!!

thank you very much guy !!! 🙂

Regards,

Karther
