# Custom credential injectors

**URL:** <https://forum.ansible.com/t/custom-credential-injectors/28879>\
**Category:** AWX Project\
**Created:** [October 27, 2018, 3:27am UTC](https://forum.ansible.com/t/custom-credential-injectors/28879 "2018-10-27T03:27:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thatsatechnique](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thatsatechnique](https://forum.ansible.com/u/thatsatechnique)\
**Post date:** [October 27, 2018, 3:27am UTC](https://forum.ansible.com/t/custom-credential-injectors/28879/1 "2018-10-27T03:27:27Z")

</div>

I am having a heck of a time getting a custom credential to ‘inject’ a variable into a playbook. Let’s take an example…

fields:

- secret: true  
type: string  
id: slack\_token  
label: slack\_token

- secret: false  
type: string  
id: slack\_message  
label: slack\_message  
required:

- slack\_token

INJECTORS:  
extra\_vars:  
SLACK\_MESSAGE: ‘{{slack\_message}}’  
SLACK\_TOKEN: ‘{{slack\_token}}’

So in my playbook, using the slack module, I should be able to use:  
token: " {{ SLACK\_TOKEN }} "

When running the playbook, however, I get:  
“msg”: " failed to send {"username": "Ansible", "text": " This is just a test. ", "link\_names": 1, "icon\_url": "[https://www.ansible.com/favicon.ico\](https://www.ansible.com/favicon.ico%5C)“} to [https://hooks.slack.com/services/[obscured]:](https://hooks.slack.com/services/%5Bobscured%5D:) HTTP Error 400: Bad request”

One somewhat unique thing about the Slack token specifically, is that it has \ in there (i.e. thetoken/generatedby/slack) - maybe an escaping error??

Can anyone confirm custom credentials work with special characters or not?

---

<div class="post-metadata">

**Author:** ![jowestco](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jowestco](https://forum.ansible.com/u/jowestco)\
**Post date:** [October 29, 2018, 4:46pm UTC](https://forum.ansible.com/t/custom-credential-injectors/28879/2 "2018-10-29T16:46:13Z")

</div>

If there are special characters in the obscured part and you are trying to make a URL call with it it could be an issue.  
Try sending your token variable through the urlencode filter before appending it to the URL:  
token: {{ SLACK\_TOKEN | urlencode }}"

Depending on your / you may need to do more. Urlencode will encode a \ but not a / (thats a valid URL entity). So if you really have a / and it need to be encoded you may be able to append regex\_replace(‘/’,’%2F’) to the filter (according to [https://lookonmyworks.co.uk/2016/01/12/ansible-templates-and-urlencode/](https://lookonmyworks.co.uk/2016/01/12/ansible-templates-and-urlencode/))

-John

---

<div class="post-metadata">

**Author:** ![David\_Maple](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@David\_Maple](https://forum.ansible.com/u/David_Maple)\
**Post date:** [October 30, 2018, 11:28am UTC](https://forum.ansible.com/t/custom-credential-injectors/28879/3 "2018-10-30T11:28:12Z")

</div>

I believe you have a different problem. The Slack token has forward slashes in it ‘/‘ and the should not be escaped because they become pard of the URI sent to [hooks.slack.com](http://hooks.slack.com). I haven’t seen any tokens with backslash ‘\’ in them.

It sounds like you’re trying to use a credential within a playbook and I have not seen that done. So, I can’t be much more help than that.

We store our slack tokens in regular variables. They are then applied in a playbook to the Slack module. You may also want to consider using Slack Notification in AWX. It’s a little limited, but may help.

Dave

---

<div class="post-metadata">

**Author:** ![thatsatechnique](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thatsatechnique](https://forum.ansible.com/u/thatsatechnique)\
**Post date:** [October 30, 2018, 11:48pm UTC](https://forum.ansible.com/t/custom-credential-injectors/28879/4 "2018-10-30T23:48:00Z")

</div>

That’s exactly why I was hoping this would be an easy answer :). The notifications within AWX are good for success/fail, but there are some intermediate (and/or tailored) notifications I’d like to push. We can do this by, like you say, adding it as a variable within the job template, but that’s not very secure. The appearance of the notifications setup looks like it’s being put into (and ultimately used from) the vault - value == $encrypted$ I figured the entire idea behind injectors was exactly this: [https://docs.ansible.com/ansible-tower/latest/html/userguide/credential\_types.html#create-a-new-credential-type](https://docs.ansible.com/ansible-tower/latest/html/userguide/credential_types.html#create-a-new-credential-type)

Anyway, I appreciate the responses - will keep playing with it!
