# Best way to pass the password to dynamic inventory script

**URL:** <https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106>\
**Category:** Ansible Project\
**Created:** [April 12, 2019, 3:27pm UTC](https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106 "2019-04-12T15:27:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumar4](https://avatars.discourse-cdn.com/v4/letter/k/d9b06d/32.png) [@Kumar4](https://forum.ansible.com/u/Kumar4)\
**Post date:** [April 12, 2019, 3:27pm UTC](https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106/1 "2019-04-12T15:27:39Z")

</div>

Hello ,

I have created a dynamic inventory script and it requires credentials for login and pull the host names.  
So what is the best way to pass credentials to dynamic inventory script.  
I have seen some docs on ansible doco where passing credentials from .ini file as plain text.  
Also i have seen exporting as environment variables.  
Can i use something like encryption module in python or are there any best practices.

Thanks,  
Kumar.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 18, 2019, 4:14pm UTC](https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106/2 "2019-04-18T16:14:45Z")

</div>

I would recommend using an inventory plugin instead, then you can use  
a vaulted inventory source with the credentials.

---

<div class="post-metadata">

**Author:** ![Kumar4](https://avatars.discourse-cdn.com/v4/letter/k/d9b06d/32.png) [@Kumar4](https://forum.ansible.com/u/Kumar4)\
**Post date:** [April 19, 2019, 1:58am UTC](https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106/3 "2019-04-19T01:58:40Z")

</div>

I have already developed a scirpt. And plugin wont work in our current solution. I do not have plugins from ansible to use.  
So i developed a scirpt. Still need a solution to pass credentials to dynamicinventoryscirpt.py

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 23, 2019, 2:38am UTC](https://forum.ansible.com/t/best-way-to-pass-the-password-to-dynamic-inventory-script/30106/4 "2019-04-23T02:38:12Z")

</div>

Well, scripts are used via the 'script' plugin, so you are already  
using plugins. Scripts are very easy to create, they just need to  
output properly formatted JSON, but the problem with scripts, is that  
the are externally executed and cannot use facilities (like vault)  
that Ansible provides. Inventory plugins are a little harder to  
create, but have access to many more features from inside Ansible.
