# Inject credentials to playbook

**URL:** <https://forum.ansible.com/t/inject-credentials-to-playbook/29672>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [February 13, 2019, 4:30pm UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672 "2019-02-13T16:30:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![laya.guerinw](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@laya.guerinw](https://forum.ansible.com/u/laya.guerinw)\
**Post date:** [February 13, 2019, 4:30pm UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672/1 "2019-02-13T16:30:51Z")

</div>

Hi All

I have followed the instructions here: [https://www.ansible.com/blog/ansible-tower-feature-spotlight-custom-credentials](https://www.ansible.com/blog/ansible-tower-feature-spotlight-custom-credentials)

on my template I have added the extra vars:

extra\_vars:  
AD\_Admin\_password: ‘{{ password }}’  
AD\_Admin\_username: ‘{{ username }}’

but when I run the playbook I get:

{  
“msg”: “The task includes an option with an undefined variable. The error was: ‘AD\_Admin\_username’ is undefined\n\nThe error appears to have been in ‘/var/lib/awx/projects/\_8\_\_ad\_realm/realm\_dev\_env.yml’: line 33, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Join system to AD and add the computer object in the Linux OU\n ^ here\n”,  
“\_ansible\_no\_log”: false  
}

any idea why the credentials aren’t getting passed to the playbook?

- name: Join system to AD and add the computer object in the Linux OU  
expect:  
command: /usr/sbin/realm join [domain.com](http://domain.com) --user=‘{{ AD\_Admin\_username }}’ --computer-ou=“OU=Linux,OU=Servers,OU=Machines,DC=domain,DC=com”  
responses:  
Password for \*: ‘{{ AD\_Admin\_password }}’

---

<div class="post-metadata">

**Author:** ![innatenew](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@innatenew](https://forum.ansible.com/u/innatenew)\
**Post date:** [February 13, 2019, 11:48pm UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672/2 "2019-02-13T23:48:04Z")

</div>

I have been stuck with this few days back

Steps that worked for me:

Create custom credentials  
Attach those credential to your playbook template  
Use the keys from the credentials in your playbook

---

<div class="post-metadata">

**Author:** ![Foley\_John](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@Foley\_John](https://forum.ansible.com/u/Foley_John)\
**Post date:** [February 14, 2019, 2:02am UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672/3 "2019-02-14T02:02:10Z")

</div>

Can you post the contents of your custom credential? Like the injectors, etc.

---

<div class="post-metadata">

**Author:** ![laya.guerinw](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@laya.guerinw](https://forum.ansible.com/u/laya.guerinw)\
**Post date:** [February 14, 2019, 8:19am UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672/4 "2019-02-14T08:19:44Z")

</div>

input configuration:

fields:

- id: username  
type: string  
label: AD Admin username
- id: password  
type: string  
label: AD Admin password  
secret: true  
required:
- username
- password

injector configuration:

extra\_vars:  
AD\_Admin\_password: ‘{{ password }}’  
AD\_Admin\_username: ‘{{ username }}’

Should I be defining the variable somewhere in the playbook or should putting the extra vars on the template be enough?

---

<div class="post-metadata">

**Author:** ![Uriel](https://avatars.discourse-cdn.com/v4/letter/u/53a042/32.png) [@Uriel](https://forum.ansible.com/u/Uriel)\
**Post date:** [February 14, 2019, 4:49pm UTC](https://forum.ansible.com/t/inject-credentials-to-playbook/29672/5 "2019-02-14T16:49:55Z")

</div>

Your custom credential looks about right… I think there’s just a misunderstanding about using it. You wrote:

> on my template I have added the extra vars:
> 
> extra\_vars:  
> AD\_Admin\_password: ‘{{ password }}’  
> AD\_Admin\_username: ‘{{ username }}’

Instead of adding the vars to the template, you need to create a credential of the custom credential type you’re defining and add that credential to the template.
