# Reading config file in a plugin

**URL:** <https://forum.ansible.com/t/reading-config-file-in-a-plugin/5163>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [April 25, 2024, 8:39pm UTC](https://forum.ansible.com/t/reading-config-file-in-a-plugin/5163 "2024-04-25T20:39:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Ratliff](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/john_ratliff/32/3007_2.png) [@John\_Ratliff](https://forum.ansible.com/u/John_Ratliff)\
**Post date:** [April 25, 2024, 8:39pm UTC](https://forum.ansible.com/t/reading-config-file-in-a-plugin/5163/1 "2024-04-25T20:39:22Z")

</div>

How can I read a config file from a plugin? I tried opening the file, but the CWD is the directory I launched my playbook from. I can get the playbook directory, but if they called my plugin from a playbook outside the collection, this may not help me traverse to the plugins folder in my collection.

Is there some way to get the plugin path or the collection path?

I want to do something like this:

class LookupModule(LookupBase):  
def run(self, terms, variables=None, \*\*kwargs):  
with open(‘config.yaml’, ‘r’) as f:  
c = yaml.safe\_load(f)

# do something with c

Is there some way I can know where config.yaml will be relative to the LookupModule file so I can open it?

Thanks,

–John

---

<div class="post-metadata">

**Author:** ![John\_Ratliff](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/john_ratliff/32/3007_2.png) [@John\_Ratliff](https://forum.ansible.com/u/John_Ratliff)\
**Post date:** [May 4, 2024, 6:33pm UTC](https://forum.ansible.com/t/reading-config-file-in-a-plugin/5163/2 "2024-05-04T18:33:49Z")

</div>

I ended up using **file** from python.
