# access to original username via variable

**URL:** <https://forum.ansible.com/t/access-to-original-username-via-variable/12141>\
**Category:** Ansible Project\
**Created:** [December 16, 2012, 8:15pm UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141 "2012-12-16T20:15:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Snapp](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Christopher\_Snapp](https://forum.ansible.com/u/Christopher_Snapp)\
**Post date:** [December 16, 2012, 8:15pm UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141/1 "2012-12-16T20:15:40Z")

</div>

I’d like to know if it would be possible to surface the username of the original account that has logged into the system to perform the given tasks via a fact.

This would be useful in writing the username to a log entry on the machine during playbook execution; or something more useful would be that it would allow the use of ‘when\_string’ conditionals based on the user executing the playbook.

I would think a “fact” named “ansible\_remoteuser” would be sufficient.

---

<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:** [December 17, 2012, 5:37pm UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141/2 "2012-12-17T17:37:57Z")

</div>

We could populate this on the server side like some of the other  
variables (inventory\_hostname, etc, is similar magic).

Guessing it should be set as "$ansible\_ssh\_user" and only set for the  
SSH connection types.

--Michael

---

<div class="post-metadata">

**Author:** ![Christopher\_Snapp](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Christopher\_Snapp](https://forum.ansible.com/u/Christopher_Snapp)\
**Post date:** [December 20, 2012, 2:07am UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141/3 "2012-12-20T02:07:03Z")

</div>

Certainly my original use case was thinking of ssh connection types.  
I'm wondering if it is invalid to expect to have the username of the  
underlying account running the ansible process always available  
though. Typically in fireball it may be run as root and you wouldn't  
be able to derive the original account that sudo'd up to establish the  
0mq session, but isn't that still valid in a sense? The same goes for  
local runs, isn't it still worth surfacing the results of `logname`?  
If that is a semi-sane request would it make sense just to call it  
ansible\_logname if only because it maps to the \*nix command that  
provides the value?

---

<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:** [December 20, 2012, 1:01pm UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141/4 "2012-12-20T13:01:11Z")

</div>

> Certainly my original use case was thinking of ssh connection types.  
> I'm wondering if it is invalid to expect to have the username of the  
> underlying account running the ansible process always available  
> though. Typically in fireball it may be run as root and you wouldn't  
> be able to derive the original account that sudo'd up to establish the  
> 0mq session, but isn't that still valid in a sense? The same goes for  
> local runs, isn't it still worth surfacing the results of `logname`?  
> If that is a semi-sane request would it make sense just to call it  
> ansible\_logname if only because it maps to the \*nix command that  
> provides the value?

ansible\_user then ... but I don't care for ansible\_logname so much.

---

<div class="post-metadata">

**Author:** ![Christopher\_Snapp](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Christopher\_Snapp](https://forum.ansible.com/u/Christopher_Snapp)\
**Post date:** [December 20, 2012, 1:29pm UTC](https://forum.ansible.com/t/access-to-original-username-via-variable/12141/5 "2012-12-20T13:29:40Z")

</div>

ansible\_user sounds good...I'd agree ansible\_logname is pretty lame,  
it was just an idea since someone thought it was a good name for a  
command.
