# Reading INI inventory file from S3

**URL:** <https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725>\
**Category:** Ansible Developer\
**Tags:** azure, aws\
**Created:** [February 13, 2018, 9:33pm UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725 "2018-02-13T21:33:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Archit\_Baweja](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Archit\_Baweja](https://forum.ansible.com/u/Archit_Baweja)\
**Post date:** [February 13, 2018, 9:33pm UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/1 "2018-02-13T21:33:44Z")

</div>

Hey all,

In my workflow at work, we us Ansible for managing dynamically provisioned Azure VMs after they’re provisioned. Currently our provisioning scripts setup the Azure VMs, and then generate an ansible inventory file, which we store in AWS S3. This way, any of the operations folks who want to run post provisioning playbooks, they go download the inventory file from AWS S3, and then run the playbooks using the regular syntax `ansible-playbook a-playbook.yml -i path/to/downloaded/inventory/file`.

We recently upgraded to Ansible 2.4, and was wondering, that given the new inventory plugin refactor, if it would be possible for me to write a plugin, that wraps the INI plugin, but does the automatic download of the inventory from the AWS S3 source. How would I go about doing it? Specifically…

1. Can I write my custom inventory plugin in my `lib/` directory, and Ansible will pick it up? Or is there another path where it looks for inventory plugins.
2. Is there any documentation on writing a custom plugin, including the interface of expected method calls and return values?
3. Bonus, does the current design allow me to “compose” (in the sense of functional programming) plugins over existing plugins?

So for example in my case, I would just add a wrapper plugin class (or maybe a child class of the INI plugin), and add the logic to download the inventory file. Specifically something that would work with the command line `ansible-playbook my-playbook.yml -i s3://my-bucket/inventory/path`.

Thanks in advance,  
Archit

P.S. Note the basic idea I’m going for is not really an Inventory plugin,as much as writing an inventory lookup plugin.

---

<div class="post-metadata">

**Author:** ![Josiah\_Niedrauer](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@Josiah\_Niedrauer](https://forum.ansible.com/u/Josiah_Niedrauer)\
**Post date:** [February 13, 2018, 10:17pm UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/2 "2018-02-13T22:17:19Z")

</div>

You shouldn’t need a plugin for this. Use a script which downloads and prints the inventory to stdout as your inventory file.

For example:  
ansible-playbook -i script.sh

---

<div class="post-metadata">

**Author:** ![Archit\_Baweja](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Archit\_Baweja](https://forum.ansible.com/u/Archit_Baweja)\
**Post date:** [February 14, 2018, 12:27am UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/3 "2018-02-14T00:27:28Z")

</div>

Josiah, oh interesting. I tried it but I got an error “Failed to parse /my/path/to/script with script plugin: … Syntax error while loading YAML”.

Does it expect YAML/JSON output?

---

<div class="post-metadata">

**Author:** ![Josiah\_Niedrauer](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@Josiah\_Niedrauer](https://forum.ansible.com/u/Josiah_Niedrauer)\
**Post date:** [February 14, 2018, 1:23am UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/4 "2018-02-14T01:23:34Z")

</div>

Had to look up the documentation. Looks like it expects json output: [http://docs.ansible.com/ansible/latest/dev\_guide/developing\_inventory.html](http://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html)

Sorry about that. I guess it’s not a perfect fit for your use case (INI file in S3)

---

<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:** [February 15, 2018, 1:39am UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/5 "2018-02-15T01:39:02Z")

</div>

Or you can just 'mount' s3 as a 'local drive' and point at it for inventory.

If you still want to 'autodownload' you might want to use an inventory  
plugin instead of an inventory script.

---

<div class="post-metadata">

**Author:** ![Archit\_Baweja](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Archit\_Baweja](https://forum.ansible.com/u/Archit_Baweja)\
**Post date:** [February 15, 2018, 5:00am UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/6 "2018-02-15T05:00:39Z")

</div>

Brian,

Exactly! I was trying to cook up a custom inventory plugin , by composing the existing ones. So back to my original question, where can I get some docs for writing one, or is reading the source of existing ones is the best idea.

Thanks in advance,  
Archit

---

<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:** [February 15, 2018, 3:55pm UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/7 "2018-02-15T15:55:55Z")

</div>

Writing the docs on how to write them is 'on my list'....

---

<div class="post-metadata">

**Author:** ![Archit\_Baweja](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Archit\_Baweja](https://forum.ansible.com/u/Archit_Baweja)\
**Post date:** [February 15, 2018, 9:19pm UTC](https://forum.ansible.com/t/reading-ini-inventory-file-from-s3/26725/8 "2018-02-15T21:19:39Z")

</div>

@Brian, I can help you write them, if you can guide me to some initial info, or style of.

Otherwise I was thinking of doing a blog style article on this, one I code up my inventory plugin based on reading the source code.
