Load variables from group_vars/all in custom module

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

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

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ł:

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

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ł: