# with\_inventory\_hostnames and Ansible Vault

**URL:** <https://forum.ansible.com/t/with-inventory-hostnames-and-ansible-vault/18116>\
**Category:** Ansible Project\
**Created:** [April 28, 2015, 8:49pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-ansible-vault/18116 "2015-04-28T20:49:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![klynch](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@klynch](https://forum.ansible.com/u/klynch)\
**Post date:** [April 28, 2015, 8:49pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-ansible-vault/18116/1 "2015-04-28T20:49:38Z")

</div>

I am trying to use the with\_inventory\_hostnames lookup plugin, but it keeps failing with the folllowing error: “A vault password must be specified to decrypt /opt/ansible/group\_vars/secure\_vault”

A workaround was to modify the LookupModule to provide the vault\_password to the inventory. Is this the correct approach?

`

class LookupModule(object):

def **init** (self, basedir=None, \*\*kwargs):  
self.basedir = basedir  
if ‘runner’ in kwargs:  
self.host\_list = kwargs[‘runner’].inventory.host\_list  
self.vault\_pass = kwargs[‘runner’].vault\_pass  
else:  
raise errors.AnsibleError(“inventory\_hostnames must be used as a loop. Example: "with\_inventory\_hostnames: 'all'"”)

def run(self, terms, inject=None, \*\*kwargs):  
terms = utils.listify\_lookup\_plugin\_terms(terms, self.basedir, inject)

if not isinstance(terms, list):  
raise errors.AnsibleError(“with\_inventory\_hostnames expects a list”)  
return flatten(inventory.Inventory(self.host\_list, vault\_password=self.vault\_pass).list\_hosts(terms))

`

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [June 19, 2015, 10:17am UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-ansible-vault/18116/2 "2015-06-19T10:17:31Z")

</div>

I think you would have a better shot at an answer if you’d ask here: [https://groups.google.com/forum/#!forum/ansible-devel](https://groups.google.com/forum/#!forum/ansible-devel)
