# User that runs ansible

**URL:** <https://forum.ansible.com/t/user-that-runs-ansible/13053>\
**Category:** Ansible Project\
**Created:** [July 2, 2013, 11:53am UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053 "2013-07-02T11:53:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [July 2, 2013, 11:53am UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/1 "2013-07-02T11:53:17Z")

</div>

Hi,

How do I get the local user in an variable? My usercase:

- name: Make sure my authorized key is installed  
authorized\_key: user=${USER} key=“{{ lookup(‘file’, ‘/home/’ + $USER + ‘/.ssh/id\_rsa.pub’) }}”

Thanks,

Mathias

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [July 2, 2013, 12:40pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/2 "2013-07-02T12:40:49Z")

</div>

> How do I get the local user in an variable? My usercase:

Look for the ENV lookup: $ENV(USER)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [July 2, 2013, 1:29pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/3 "2013-07-02T13:29:34Z")

</div>

Thanks! But it fails:

msg: Failed to lookup user ${ENV(USER)}: ‘getpwnam(): name not found: ${ENV(USER)}’  
failed: [hdata01] =\> {“failed”: true, “item”: “”}

Any idea?

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [July 2, 2013, 1:32pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/4 "2013-07-02T13:32:09Z")

</div>

It works like this:

- name: Make sure my authorized key is installed

authorized\_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘/home/’ + $ENV(USER) + ‘/.ssh/id\_rsa.pub’) }}”

but the key doesn’t evaluate. The lookup doesn’t work. My remote file contains

{{lookup(‘file’, ‘/home/’ + mathias + ‘/.ssh/id\_rsa.pub’)}}

?

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [July 2, 2013, 1:32pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/5 "2013-07-02T13:32:32Z")

</div>

> msg: Failed to lookup user ${ENV(USER)}: 'getpwnam(): name not found:  
> ${ENV(USER)}'  
> failed: [hdata01] =\> {"failed": true, "item": ""}

getpwnam() failed?! Is this a Unix system you're running on? 😉  
What OS/version?

Can you try

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- local\_action: debug msg="Hello $ENV(HOME)"

and run ansible-playbook -vvv

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [July 2, 2013, 1:38pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/6 "2013-07-02T13:38:45Z")

</div>

Yeah, it’s an Ubuntu 12.10.

But it works like this:

- name: Make sure my authorized key is installed

authorized\_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘/home/’ + $ENV(USER) + ‘/.ssh/id\_rsa.pub’) }}”

but the key doesn’t evaluate. The lookup doesn’t work. My remote authorized\_keys now contains

{{lookup(‘file’, ‘/home/’ + mathias + ‘/.ssh/id\_rsa.pub’)}}

which doesn’t work…

---

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [July 2, 2013, 1:40pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/7 "2013-07-02T13:40:22Z")

</div>

This works:

- name: Make sure my local RSA SSH key is installed  
authorized\_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘~/.ssh/id\_rsa.pub’) }}”

Thanks!!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 2, 2013, 6:26pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/8 "2013-07-02T18:26:17Z")

</div>

Friendly reminder:

$ENV(USER) as a mechanism of getting lookup plugins is deprecated

We should be instructing folks do to:

{{ lookup(‘env’, ‘USER’) }}

---

<div class="post-metadata">

**Author:** ![patte](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@patte](https://forum.ansible.com/u/patte)\
**Post date:** [May 14, 2014, 11:28pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/9 "2014-05-14T23:28:28Z")

</div>

Hi! For me it doesn’t!  
Neither this:  
authorized\_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘~/.ssh/id\_rsa.pub’) }}”  
nor this:  
authorized\_key: user={{ lookup(‘env’, ‘USER’) }} key=“{{ lookup(‘file’, ‘~/.ssh/id\_rsa.pub’) }}”

both fail with:  
failed: [dev] =\> {“failed”: true, “item”: “”}  
msg: Failed to lookup user patte: ‘getpwnam(): name not found: patte’

I’m patte on OSX, with ansible 1.5.5 fired by vagrant provision  
any idea?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 14, 2014, 11:45pm UTC](https://forum.ansible.com/t/user-that-runs-ansible/13053/10 "2014-05-14T23:45:18Z")

</div>

This seems unrelated and you’re replying to an old thread, but please try this on Ansible 1.6 (so you’re using a recently released version) and give us some steps to reproduce this, perhaps.

Thanks!
