# Load variables from group\_vars/all in custom module

**URL:** <https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580>\
**Category:** Ansible Developer\
**Created:** [February 15, 2016, 10:44am UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580 "2016-02-15T10:44:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerhardjadzkadzikise](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@gerhardjadzkadzikise](https://forum.ansible.com/u/gerhardjadzkadzikise)\
**Post date:** [February 15, 2016, 10:44am UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580/1 "2016-02-15T10:44:18Z")

</div>

Hello,

I am developing custom ansible module to do something and i will implement this module as one of task in my new role.  
The new custom module is written in python 2.7.

And quick question is, how to get variables stored in group\_vars/all file in this (python) custom module?

I know that custom module has no natively access to this variables but how do you guys resolve this right now? Any ideas?

Regards,  
Gerhard

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 15, 2016, 11:48am UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580/2 "2016-02-15T11:48:52Z")

</div>

Does the module need to do something on the ansible host, or one of your managed machines?

One simple way to do this would be to make a role to wrap what your custom task is intended to do.

The role would have access to the group vars and could then pass the relevant parameter to your custom module.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![gerhardjadzkadzikise](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@gerhardjadzkadzikise](https://forum.ansible.com/u/gerhardjadzkadzikise)\
**Post date:** [February 15, 2016, 12:19pm UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580/3 "2016-02-15T12:19:58Z")

</div>

No. This module will communicate with some API via network. Everything will be done on local. And for example i need to have login/pass to authenticate, IP of API etc. So i know that i can in playbook send all variables from defaul\_vars/all to custom module via arguments but i would like to have some possibility to access to this variables in python instead of passing them as arguments in playbook.

W dniu poniedziałek, 15 lutego 2016 12:48:52 UTC+1 użytkownik jhawkesworth napisał:

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 15, 2016, 1:25pm UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580/4 "2016-02-15T13:25:19Z")

</div>

Maybe a callback plugin might do what you need then?

callbacks allways run on the ansible controller and you can access host and group vars from them.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![gerhardjadzkadzikise](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@gerhardjadzkadzikise](https://forum.ansible.com/u/gerhardjadzkadzikise)\
**Post date:** [February 15, 2016, 1:47pm UTC](https://forum.ansible.com/t/load-variables-from-group-vars-all-in-custom-module/20580/5 "2016-02-15T13:47:34Z")

</div>

Yes, i can write callback plugin instead of ansible module but it is not the case right now.  
So maybe from other side:

How to get realpath of executed python custom module in code? In ENV variables i only found PWD which points me to directory from which i run the ansible-playbook ?  
I want to put some yaml file loader in code in order to parse the yml file.

W dniu poniedziałek, 15 lutego 2016 14:25:19 UTC+1 użytkownik jhawkesworth napisał:
