# Environment Variables - Slack.py

**URL:** <https://forum.ansible.com/t/environment-variables-slack-py/20448>\
**Category:** Ansible Project\
**Created:** [February 4, 2016, 1:28pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448 "2016-02-04T13:28:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 4, 2016, 1:28pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/1 "2016-02-04T13:28:29Z")

</div>

Hi @sivel

I am trying to get an Slack callback plugin to work ([https://github.com/sivel/ansible/blob/slack-callback/plugins/callbacks/slack.py#L142-L147](https://github.com/sivel/ansible/blob/slack-callback/plugins/callbacks/slack.py#L142-L147)), but I am getting the following error:#

Unexpected Exception: ‘module’ object has no attribute ‘warning’

You can see the what I am trying to achieve here: [https://github.com/ansible/ansible/pull/8955](https://github.com/ansible/ansible/pull/8955)

When looking at the file I see that it mentions the following:

class CallbackModule(object):

“”"This is an example ansible callback plugin that sends status

updates to a Slack channel during playbook execution.

This plugin makes use of the following environment variables:

SLACK\_TOKEN (required): Slack Integration token

SLACK\_TEAM (required): Slack team name [TEAM.slack.com](http://TEAM.slack.com)

SLACK\_CHANNEL (optional): Slack room to post in. Default: #ansible

SLACK\_USERNAME (optional): Username to post as. Default: ansible

Requires:

prettytable

“”"

Where would I need to insert these SLACK environment variables in order for this file to access this information?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 4, 2016, 1:47pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/2 "2016-02-04T13:47:39Z")

</div>

Those environment variables need to be set in the shell that you execute Ansible from. Also that branch/PR that you reference is for Ansible 1.9. If you need a version that works with Ansible 2.0, see [https://github.com/ansible/ansible/pull/13408](https://github.com/ansible/ansible/pull/13408)

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 4, 2016, 2:07pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/3 "2016-02-04T14:07:16Z")

</div>

Hi Matt

I have now updated the slack.py with the following code ([https://github.com/sivel/ansible/blob/v2-slack-callback/lib/ansible/plugins/callback/slack.py](https://github.com/sivel/ansible/blob/v2-slack-callback/lib/ansible/plugins/callback/slack.py)), as I am running Ansible v2.

I have added the environmental variables into a ver basic playbook to see if it posts the results to Slack (see below):

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 4, 2016, 2:12pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/4 "2016-02-04T14:12:25Z")

</div>

In Ansible v2 you must whitelist callback plugins in ansible.cfg. Additionally, the environment vars must be set in your shell, not in the playbook.

In bash this would be done from a .bash\_profile or directly on the command line by using:

export SLACK\_TOKEN=mytoken

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 4, 2016, 2:45pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/5 "2016-02-04T14:45:27Z")

</div>

Hi Matt

Thanks for your quick responses.

I have now added SLACK\_WEBHOOK\_URL and SLACK\_CHANNEL to the environment var in the shell

SLACK\_TOKEN=[https://hooks.slack.com/services/xxxxxx/yyyyyyyy/token](https://hooks.slack.com/services/xxxxxx/yyyyyyyy/token)  
SLACK\_CHANNEL=#ansible

I have also added the withlist entry into ansible.cfg:

# set plugin path directories here, separate with colons

action\_plugins = /usr/share/ansible\_plugins/action\_plugins  
callback\_plugins = /usr/share/ansible\_plugins/callback\_plugins  
connection\_plugins = /usr/share/ansible\_plugins/connection\_plugins  
lookup\_plugins = /usr/share/ansible\_plugins/lookup\_plugins  
vars\_plugins = /usr/share/ansible\_plugins/vars\_plugins  
filter\_plugins = /usr/share/ansible\_plugins/filter\_plugins

callback\_whitelist = slack.py

I then try run the playbook:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 4, 2016, 3:12pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/6 "2016-02-04T15:12:14Z")

</div>

I think the whitelist is just slack without the file extension.

Also, if you run Ansible with higher verbosity, it will show you which callbacks are being loaded.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 4, 2016, 3:54pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/7 "2016-02-04T15:54:52Z")

</div>

you should not need to whitelist custom plugins, that was done only  
for the plugins shipped with ansible (which have a variable that  
indicates they NEED the whitelist to work).

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 4, 2016, 3:55pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/8 "2016-02-04T15:55:27Z")

</div>

All working mate! Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 8, 2016, 5:40pm UTC](https://forum.ansible.com/t/environment-variables-slack-py/20448/9 "2016-02-08T17:40:40Z")

</div>

Hi guys

This is working perfectly running playbooks from the server. But when I run any playbooks from Ansible Tower nothing is being send to Slack.

Is there something that you know that needs to be done in order for this to work?

Cheers  
Mark
