# Access to variables defined in roles from python script

**URL:** <https://forum.ansible.com/t/access-to-variables-defined-in-roles-from-python-script/29837>\
**Category:** Ansible Project\
**Created:** [March 7, 2019, 9:09am UTC](https://forum.ansible.com/t/access-to-variables-defined-in-roles-from-python-script/29837 "2019-03-07T09:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wnelis294](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@wnelis294](https://forum.ansible.com/u/wnelis294)\
**Post date:** [March 7, 2019, 9:09am UTC](https://forum.ansible.com/t/access-to-variables-defined-in-roles-from-python-script/29837/1 "2019-03-07T09:09:33Z")

</div>

I am an ansible newbie. My first non-trivial ansible project is to update / optimize the configuration of Juniper switches. The ansible modules are not run on the Juniper switch but locally on the ansible controller. The default modules do not seem to match our requirements, thus a (python) user module is needed. In a role ( ~/roles/x/vars/main.yaml ) a multi-level dict (in python-parlance) is defined, which includes a few lists. Is this information accessible from within a python script running on the ansible controller, and if so, how?

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [March 7, 2019, 9:56am UTC](https://forum.ansible.com/t/access-to-variables-defined-in-roles-from-python-script/29837/2 "2019-03-07T09:56:52Z")

</div>

Hi,

Have a look here: [https://docs.ansible.com/ansible/latest/dev\_guide/developing\_modules\_general.html](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html)  
You’ll need to build your own module that you can invoke from your task list or role.

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![wnelis294](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@wnelis294](https://forum.ansible.com/u/wnelis294)\
**Post date:** [March 11, 2019, 11:43am UTC](https://forum.ansible.com/t/access-to-variables-defined-in-roles-from-python-script/29837/3 "2019-03-11T11:43:41Z")

</div>

I’ve read it, as well as other documents w.r.t. development of user modules. However, it does not answer my original question, nor does it supply a pointer to an answer.  
In the mean time an related question has come up. On remote machines one can save some ‘facts’ in /etc/ansible/facts.d/\*fact. Is a similar functionality also available on the ansible controller?
