# How can I use the AWX credential variables in playbooks?

**URL:** <https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268>\
**Category:** AWX Project\
**Tags:** aws, awx\
**Created:** [April 12, 2018, 10:57pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268 "2018-04-12T22:57:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [April 12, 2018, 10:57pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/1 "2018-04-12T22:57:42Z")

</div>

How can I use the AWX credential variables in playbooks?

Im specifically looking to re-use the AWS Credential keys in a playbook that uses ‘ec2\_instance\_facts’ which requires the passing of the keys in order to work.

Thanks!

Brent

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [April 16, 2018, 3:32pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/2 "2018-04-16T15:32:20Z")

</div>

In the case of the AWS credentials they’ll be attached to a job run using the standard environment variables that the ec2 modules expect: AWS\_ACCESS\_KEY and AWS\_SECRET\_KEY

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [April 16, 2018, 4:08pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/3 "2018-04-16T16:08:09Z")

</div>

I must be doing something wrong or mis-understanding how to access the variable.

My Example,

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [April 16, 2018, 4:14pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/4 "2018-04-16T16:14:03Z")

</div>

I realized after posting below, that I was not using the variable for the secret like you mentioned. I fixed the code and reran it.

I changed my code from “AWS\_SECRET\_ACCESS\_KEY” to “AWS\_SECRET\_KEY”

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [April 17, 2018, 10:43pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/5 "2018-04-17T22:43:55Z")

</div>

You need to look up the environment variables, they aren’t added as extra vars:

[https://docs.ansible.com/ansible/2.5/plugins/lookup/env.html](https://docs.ansible.com/ansible/2.5/plugins/lookup/env.html)

I will point out, however, that the ec2 modules use boto which will automatically pick them up out of the environment… have you tried running the playbook in AWX _without_ setting aws\_access\_key and aws\_secret\_key?

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [April 18, 2018, 2:40pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/6 "2018-04-18T14:40:44Z")

</div>

I will give the env thing a try.

When I run the AWX job without setting aws\_access\_key and aws\_secret\_key I get this error

NoCredentialsError: Unable to locate credentials

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [April 18, 2018, 8:46pm UTC](https://forum.ansible.com/t/how-can-i-use-the-awx-credential-variables-in-playbooks/27268/7 "2018-04-18T20:46:47Z")

</div>

This is what I finally got to work. Many thanks for the help and direciton 😃
