# Using lookups to fill dynamic inventory parameters

**URL:** <https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363>\
**Category:** Get Help\
**Tags:** windows\
**Created:** [June 13, 2025, 9:57am UTC](https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363 "2025-06-13T09:57:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ildjarn](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ildjarn](https://forum.ansible.com/u/ildjarn)\
**Post date:** [June 13, 2025, 9:57am UTC](https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363/1 "2025-06-13T09:57:41Z")

</div>

Hello,

I am trying to create an inventory plugin that gets info from a Windows server by running a powershell script on it.

I have the basic script running, passing the server, user, and password as parameters to the inventory source script:

```yaml
---
plugin: my_plugin
server: myserver
user: myuser
password: SuperSecretPassword

```

This works, and the inventory is created and populated successfully.

Unfortunately, the account that I need to use has a password that is randomly changed to a new password every few hours. So after a few hours, this inventory stops working.

I can get the correct password with a lookup plugin, but I have been unable to find how you can add this lookup call to the inventory source. If I add a `{{ lookup('myplugin', 'user') }}` to the inventory, the password used is that literal text.

So how do I add a password that’s evaluated at run time to an inventory source?

Joost

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [June 13, 2025, 10:35am UTC](https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363/2 "2025-06-13T10:35:37Z")

</div>

> So how do I add a password that’s evaluated at run time to an inventory source?

As the user of the plugin, you cannot, unless the plugin explicitly handles templating for that option. Some inventory plugins I know explicitly allow templating for certain fields such as username and password - but not all do.

Fortunately you’re writing that inventory plugin yourself, so you can fix this 😉 You can see an example of how to do this here: [community.general/plugins/inventory/linode.py at bc99432f893e0efcb141f660e272bebf8ccc6710 · ansible-collections/community.general · GitHub](https://github.com/ansible-collections/community.general/blob/bc99432f893e0efcb141f660e272bebf8ccc6710/plugins/inventory/linode.py#L151-L153)

---

<div class="post-metadata">

**Author:** ![ildjarn](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ildjarn](https://forum.ansible.com/u/ildjarn)\
**Post date:** [June 13, 2025, 11:01am UTC](https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363/3 "2025-06-13T11:01:01Z")

</div>

Thank you, this seems to work:

```python
        if self.templar.is_template(windows_user:=self.get_option('windows_user')):
            windows_user = self.templar.template(variable=windows_user, disable_lookups=False)
        if self.templar.is_template(windows_password:= self.get_option('windows_password')):
            windows_password = self.templar.template(variable=windows_password, disable_lookups=False)

```

---

<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:** [July 13, 2025, 11:01am UTC](https://forum.ansible.com/t/using-lookups-to-fill-dynamic-inventory-parameters/43363/4 "2025-07-13T11:01:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
