# Dynamic Inventory API keys in Vault

**URL:** <https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066>\
**Category:** Ansible Developer\
**Created:** [April 5, 2016, 10:44am UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066 "2016-04-05T10:44:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anthony](https://forum.ansible.com/u/anthony)\
**Post date:** [April 5, 2016, 10:44am UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/1 "2016-04-05T10:44:35Z")

</div>

Hi All,

Is it possible to access variables stored in vault from a dynamic inventory script?

**Problem:** I need to create a dynamic inventory composed of multiple accounts from multiple providers and would like to key several API keys in vault.

Any hints, patterns or pertinent areas of the source code to look at will be gratefully received.

Regards,

Anthony.

---

<div class="post-metadata">

**Author:** ![anthony](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anthony](https://forum.ansible.com/u/anthony)\
**Post date:** [April 5, 2016, 10:45am UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/2 "2016-04-05T10:45:36Z")

</div>

> key several API keys in vault.

\*keep several API keys in vault.

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [April 5, 2016, 11:42am UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/3 "2016-04-05T11:42:28Z")

</div>

> > **Problem:** I need to create a dynamic inventory composed of multiple accounts from multiple providers and would like to keep several API keys in vault.
> > 
> > Any hints, patterns or pertinent areas of the source code to look at will be gratefully received.

Have you read [http://docs.ansible.com/ansible/playbooks\_vault.html](http://docs.ansible.com/ansible/playbooks_vault.html) ?

This sounds like it belongs to ansible-project rather than ansible-devel.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [April 5, 2016, 11:44am UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/4 "2016-04-05T11:44:52Z")

</div>

> Have you read [http://docs.ansible.com/ansible/playbooks\_vault.html](http://docs.ansible.com/ansible/playbooks_vault.html) ?

Actually [http://docs.ansible.com/ansible/playbooks\_best\_practices.html#variables-and-vaults](http://docs.ansible.com/ansible/playbooks_best_practices.html#variables-and-vaults) as well.

---

<div class="post-metadata">

**Author:** ![anthony](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anthony](https://forum.ansible.com/u/anthony)\
**Post date:** [April 5, 2016, 12:38pm UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/5 "2016-04-05T12:38:55Z")

</div>

> > > Have you read [http://docs.ansible.com/ansible/playbooks\_vault.html](http://docs.ansible.com/ansible/playbooks_vault.html) ?

> > > Actually [http://docs.ansible.com/ansible/playbooks\_best\_practices.html#variables-and-vaults](http://docs.ansible.com/ansible/playbooks_best_practices.html#variables-and-vaults) as well.

Hi Paul, thanks for the quick response. Yes, I’ve read these. I’m comfortable with using vault in the ways described in the docs. My question is more about accessing variables from vault via the python API within a dynamic inventory.

Though, if I have missed something blatant in the docs please point it out,

Regards,

Anthony.

---

<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:** [April 5, 2016, 4:20pm UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/6 "2016-04-05T16:20:53Z")

</div>

I’d suggest having a look at

[http://docs.ansible.com/ansible/developing\_api.html#id3](http://docs.ansible.com/ansible/developing_api.html#id3)

and perhaps the vault cli implementation in lib/ansible/cli/vault.py

Jon

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [April 5, 2016, 4:42pm UTC](https://forum.ansible.com/t/dynamic-inventory-api-keys-in-vault/21066/7 "2016-04-05T16:42:53Z")

</div>

> thanks for the quick response. Yes, I’ve read these. I’m comfortable with using vault in the ways described in the docs. My question is more about accessing variables from vault via the python API within a dynamic inventory.

Ah, I misread you. I thought you maybe wanted to set per host variables based on logic in the dynamic inventory script.

Sorry for the confusion,  
Paul
