access to original username via variable

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.

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

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?

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.

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.