# user: parameter

**URL:** <https://forum.ansible.com/t/user-parameter/12180>\
**Category:** Ansible Project\
**Created:** [January 2, 2013, 12:55pm UTC](https://forum.ansible.com/t/user-parameter/12180 "2013-01-02T12:55:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [January 2, 2013, 12:55pm UTC](https://forum.ansible.com/t/user-parameter/12180/1 "2013-01-02T12:55:30Z")

</div>

Hi List,

I’m trying to run a command as a different user like so:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 2, 2013, 3:06pm UTC](https://forum.ansible.com/t/user-parameter/12180/2 "2013-01-02T15:06:19Z")

</div>

I believe you want sudo\_user. User is the one you login as.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [January 3, 2013, 6:05am UTC](https://forum.ansible.com/t/user-parameter/12180/3 "2013-01-03T06:05:51Z")

</div>

Ah ok,

I used the example from here:  
[https://gist.github.com/2897937](https://gist.github.com/2897937)

```auto

    ##########

```

```auto

    # Run things as other users!

```

```auto

    #

```

```auto

    # Each task has an optional 'user' and 'sudo' flag to indicate which

```

```auto

    # user a task should run as and whether or not to use 'sudo' to switch

```

```auto

    # to that user.

```

```auto

    - name: dump all postgres databases

```

```auto

      action: pg_dumpall -w -f /tmp/backup.psql

```

```auto

      user: postgres

```

```auto

      sudo: False

But now it does work, thanks!

```

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 3, 2013, 8:58pm UTC](https://forum.ansible.com/t/user-parameter/12180/4 "2013-01-03T20:58:41Z")

</div>

Hmm, either docs are wrong or code is not working as expected, either  
way looks like a patch (to docs or code) is needed.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [January 4, 2013, 1:04am UTC](https://forum.ansible.com/t/user-parameter/12180/5 "2013-01-04T01:04:32Z")

</div>

IIRC, only sudo\_user could be set on a task, and not user. The docs  
shouldn't imply user can be set on anything but a play, and it should  
yell at you if you try.

Though if it doesn't yell at you, I'm inclined to think it's just a  
bug that it doesn't currently work like that 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [January 4, 2013, 8:47am UTC](https://forum.ansible.com/t/user-parameter/12180/6 "2013-01-04T08:47:34Z")

</div>

Michael DeHaan wrote:

> IIRC, only sudo\_user could be set on a task, and not user. The docs  
> shouldn't imply user can be set on anything but a play, and it should  
> yell at you if you try.
> 
> Though if it doesn't yell at you, I'm inclined to think it's just a  
> bug that it doesn't currently work like that 🙂

Actually, user: is an invocation of the user module, which is why it's  
yelling at you for having two actions, so it appears to be doing the right  
thing here.

Daniel

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 4, 2013, 2:34pm UTC](https://forum.ansible.com/t/user-parameter/12180/7 "2013-01-04T14:34:51Z")

</div>

remote\_user, might be what you are looking for

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [January 7, 2013, 6:10am UTC](https://forum.ansible.com/t/user-parameter/12180/8 "2013-01-07T06:10:30Z")

</div>

Hi all,

Thanks for the feedback.

I have indeed found the sudo\_user in the [playbooks manual section](http://ansible.cc/docs/playbooks.html#basics). So it was definitely explained already, I just used the wrong documentation.  
Brian, I’m also looking for that remote\_user, to see what the difference between the two are, but I cannot seem to find any reference for it in the official documentation?  
Is the remote\_user variable not only used inside the various module’s code?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 7, 2013, 7:03am UTC](https://forum.ansible.com/t/user-parameter/12180/9 "2013-01-07T07:03:02Z")

</div>

Last I looked (a few months back) remote\_user (aka login user) gets  
evaluated at connection level w/o looking at tasks. You should be able  
to set it at host or playbook level but not at task.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [January 8, 2013, 12:57pm UTC](https://forum.ansible.com/t/user-parameter/12180/10 "2013-01-08T12:57:28Z")

</div>

Correct, plays are more or less defined as the set of the user and  
hosts/groups you are talking to a set of tasks.
