# Does -u set ansible\_ssh\_user (Ansible 1.2)

**URL:** <https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059>\
**Category:** Ansible Project\
**Created:** [July 3, 2013, 1:01pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059 "2013-07-03T13:01:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [July 3, 2013, 1:01pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/1 "2013-07-03T13:01:25Z")

</div>

Hi all,

I would like to have access to the remote user value when the -u option is specified at the command line of ansible-playbook. I am testing with the release of 1.2. When I use the following playbook test (ssh-test), I always get back my username (“jeremy”), regardless of what I set at -u.

---

<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 3, 2013, 1:04pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/2 "2013-07-03T13:04:32Z")

</div>

You are using connection local in your playbook, so it is always running as you, and not using SSH.

---

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [July 3, 2013, 1:09pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/3 "2013-07-03T13:09:06Z")

</div>

Hi Michael,

Thank you for the prompt reply. Aside from using --extra-vars to explicitly set the variable, are there any other mechanisms I could use? Ideally I would like to use -u to set ansible\_ssh\_user (or some other variable).

Thank you for your help!  
– Jeremy

---

<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 3, 2013, 1:11pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/4 "2013-07-03T13:11:45Z")

</div>

It doesn’t seem to make sense in this case as you are running locally, and as I understand it, your modules will always be running locally. You could definitely set any variable you like with --extra-vars, but it seems like you don’t want to set ansible\_ssh\_user when you aren’t SSH’ing to anything, and that would just be confusing.

If you just want to print the user you are running ansible as (that seems like it might be the use case), you can do

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

---

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [July 3, 2013, 1:16pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/5 "2013-07-03T13:16:02Z")

</div>

Hi Michael,

Ok, I understand what you are saying. I’ll fall back to using --extra-vars for this purpose.

Thank you.  
– Jeremy

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [July 3, 2013, 10:18pm UTC](https://forum.ansible.com/t/does-u-set-ansible-ssh-user-ansible-1-2/13059/6 "2013-07-03T22:18:22Z")

</div>

Ok, its a little silly, but I’ve done this before using 2 plays and the set fact module:

- hosts: all  
sudo: true  
tasks:

- name: store the ssh user name for next play  
set\_fact: ssh\_user={{ ansible\_ssh\_user}}

- hosts: all  
sudo: false  
tasks:

- local\_action: echo {{ ssh\_user }}
