# Finding out the variables for built in Credentials.

**URL:** <https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [April 25, 2020, 8:06pm UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781 "2020-04-25T20:06:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [April 25, 2020, 8:06pm UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/1 "2020-04-25T20:06:36Z")

</div>

I have a particular use case where I would like to use the existing Credentials type for other things than the built in tasks.

Example

# tower\_job\_template – create, update, or destroy Ansible Tower job template

It uses  
**tower\_host**  
**tower\_user**  
**tower\_password**

for the credentials. There is a AnsibleTower credential in AWX. Is this what the variables will be to map in the playbook?

**The documentation at**  
**[https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#ansible-tower](https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#ansible-tower)**

doesnt have any hints on it.

Any help would be helpful. Thank you all.

---

<div class="post-metadata">

**Author:** ![sdmorel](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sdmorel](https://forum.ansible.com/u/sdmorel)\
**Post date:** [April 27, 2020, 6:48am UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/2 "2020-04-27T06:48:20Z")

</div>

Reading this section of the code:  
[https://github.com/ansible/awx/blob/devel/awx/main/models/credential/\_\_init\_\_.py#L1088](https://github.com/ansible/awx/blob/devel/awx/main/models/credential/ __init__.py#L1088)

Looks like when using the credential type “Ansible Tower”, you can access the credentials in these environment variables

`  
TOWER\_HOST

TOWER\_USERNAME

TOWER\_PASSWORD

TOWER\_VERIFY\_SSL  
`

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [April 27, 2020, 7:08am UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/3 "2020-04-27T07:08:48Z")

</div>

Hi Sergio,

Thanks for the response. I am familiar with adding in extra-vars to reference a variable in a playbook, but with these environment variables…how will use it within a play to reference a variable? Is it more or less the same?

Thank you once again.

regards,

Wei-Yen

---

<div class="post-metadata">

**Author:** ![sdmorel](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sdmorel](https://forum.ansible.com/u/sdmorel)\
**Post date:** [April 27, 2020, 7:21am UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/4 "2020-04-27T07:21:19Z")

</div>

Oh, you can use the ‘env’ lookup to access the credential inside Ansible.

[https://docs.ansible.com/ansible/latest/plugins/lookup/env.html#examples](https://docs.ansible.com/ansible/latest/plugins/lookup/env.html#examples)

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [April 27, 2020, 7:25am UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/5 "2020-04-27T07:25:01Z")

</div>

ok thanks Sergio,

I;ll have a go experimenting with it. I am learning a ton

---

<div class="post-metadata">

**Author:** ![AlanCoding](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alancoding/32/301_2.png) [@AlanCoding](https://forum.ansible.com/u/AlanCoding)\
**Post date:** [April 27, 2020, 11:45am UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/6 "2020-04-27T11:45:04Z")

</div>

In your original email, you mentioned the Ansible module tower\_job\_template.

It was a specific design objective that the “Ansible Tower” credential type work with these modules. However, this has a few qualifiers.

If you run a playbook with a local connection, or delegate\_to localhost (I think), then the environment variables present when you run the ansible-playbook command will be present when the task executes. This makes perfect sense in conjunction with using an “Ansible Tower” credential (inside of AWX), because the credential injects secrets needed to interact with the API. There’s no need to run these tasks on a remote host. However, if you do run on a remote host, those environment variables will no longer be present, and you need to get around that by using the lookup plugin, as mentioned.

Similar statements apply to most of the other “cloud” type credentials.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [April 27, 2020, 7:30pm UTC](https://forum.ansible.com/t/finding-out-the-variables-for-built-in-credentials/32781/7 "2020-04-27T19:30:55Z")

</div>

Thanks Alan! This provides more clarity about how it works. So what you are saying is that the enviroment variables present themselves on the local host in this case on the container.

I am presuming then the look up plugin will have to be captured on the local host using perhaps includes and then it can be used elsewhere in the play
