# Obtain the user specified via '-u' cli option

**URL:** <https://forum.ansible.com/t/obtain-the-user-specified-via-u-cli-option/23654>\
**Category:** Ansible Project\
**Created:** [February 6, 2017, 9:04pm UTC](https://forum.ansible.com/t/obtain-the-user-specified-via-u-cli-option/23654 "2017-02-06T21:04:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Spiegle](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@Michael\_Spiegle](https://forum.ansible.com/u/Michael_Spiegle)\
**Post date:** [February 6, 2017, 9:04pm UTC](https://forum.ansible.com/t/obtain-the-user-specified-via-u-cli-option/23654/1 "2017-02-06T21:04:39Z")

</div>

At some point in Ansible 2.0.x, the ‘{{ansible\_user}}’ variable would reflect the argument passed to ansible-playbook ‘-u’. It doesn’t appear to be doing this any more, and I can’t seem to find a way to obtain the value that was passed into ‘-u’. Is there a known way to do this?

My specific use-case is that when I create a new EC2 instance, I must wait for that instance to come online before I continue my playbook. I have been using a local\_action which continually calls an ‘ssh’ client against the remote until I get a successful SSH login. I realize that most users would use a wait\_for action, but that has 2 issues:

1. If you don’t have direct network-level connectivity to the remote machine (eg, you SSH through a proxy)
2. Even if port 22 is up, it doesn’t guarantee that the host is ready to be logged into (for example, a cloud-init script might need to run in order to allow you in)

I figure that the best way to test if the instance can be logged into is to actually login to the instance. I’m open to alternatives if you have them.

Regards,  
Mike

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [February 7, 2017, 12:07pm UTC](https://forum.ansible.com/t/obtain-the-user-specified-via-u-cli-option/23654/2 "2017-02-07T12:07:54Z")

</div>

Either it is a case of wrong precedence:  
[https://docs.ansible.com/ansible/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

But I think I remember having to set the user differently:

ansible-playbook -e 'ansible\_user=foobar' ...

Johannes
