# accessing ansible.cfg variables from within modules

**URL:** <https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717>\
**Category:** Ansible Developer\
**Created:** [October 4, 2016, 11:48am UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717 "2016-10-04T11:48:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nayeem\_Syed](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nayeem\_Syed](https://forum.ansible.com/u/Nayeem_Syed)\
**Post date:** [October 4, 2016, 11:48am UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717/1 "2016-10-04T11:48:15Z")

</div>

hi there,

i am trying to access a (new custom) section from the ansible.cfg into my module, at present it seems the only way to pass parameters to the module is via the module parameter. but i need to be able to have a default that i can pass onto them that are read from the central config file. this would be useful for things like timeouts.  
in particular this PR has a timeout feature that was added in - [https://github.com/ansible/ansible-modules-extras/pull/2526](https://github.com/ansible/ansible-modules-extras/pull/2526)

I am trying to make it so that the timeout default value (in this case 10) is passed from the ansible.cfg file from a section such as ‘[maven\_artifact]’ instead of needing to edit the actual module if i want to edit the default value for the timeout.

any suggestions how this can be done?

I saw on the constants.py in the ansible repo there is a get\_config function that reads the values off the config file, but I did not see any examples in the ansible-modules-extras that is using this function or reading values off the main config as such.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 4, 2016, 4:38pm UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717/2 "2016-10-04T16:38:19Z")

</div>

Sorry, anything sent to modules must be done so as a param. If you’re writing a custom module, you could also write an action plugin which automatically passed on any such config options as params to your module, but for any modules shipped in core that’s not an option.

---

<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:** [October 4, 2016, 8:57pm UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717/3 "2016-10-04T20:57:06Z")

</div>

If you want a central location for defining some timeouts, I suggest using group\_vars/all (which can be a directory containing whatever files you need).

I store some timeout defaults in group\_vars/all, and it works fine.

---

<div class="post-metadata">

**Author:** ![Nayeem\_Syed](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nayeem\_Syed](https://forum.ansible.com/u/Nayeem_Syed)\
**Post date:** [October 5, 2016, 8:10am UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717/4 "2016-10-05T08:10:48Z")

</div>

thanks! Do you have an example of this somewhere I can look at?

---

<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:** [October 5, 2016, 8:52am UTC](https://forum.ansible.com/t/accessing-ansible-cfg-variables-from-within-modules/22717/5 "2016-10-05T08:52:39Z")

</div>

Nothing publicly available, but group\_vars/all is described a little here: [http://docs.ansible.com/ansible/playbooks\_best\_practices.html#group-and-host-variables](http://docs.ansible.com/ansible/playbooks_best_practices.html#group-and-host-variables)

Hope this helps,

Jon
