# What does the output from the dynamic inventory software look like?

**URL:** <https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 9, 2020, 8:20pm UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130 "2020-06-09T20:20:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Ward](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Martin\_Ward](https://forum.ansible.com/u/Martin_Ward)\
**Post date:** [June 9, 2020, 8:20pm UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/1 "2020-06-09T20:20:19Z")

</div>

Hi,

I am running Ansible 2.9.7 and am looking at the dynamic inventory scripts. I don’t have any of the various software listed (AWS, OpenStack etc) in the examples section and I need something where I can automatically set the remote IP address at the time that the playbook is executed, ideally after prompting the user for this information.

I have managed to craft together a simple Python script with hard-coded data (for test purposes) but I cannot fathom the output, other than it should be in JSON format. Nor can I find this documented anywhere.

Does anyone have any ideas, suggestions or pointers?

Failing that, can you suggest a way to do what I want, ask the user for the IP address of the remote server and also the software they want to install? (Yeah I know, two questions instead of one:-) )

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 9, 2020, 8:24pm UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/2 "2020-06-09T20:24:30Z")

</div>

This is largely documented at [https://docs.ansible.com/ansible/latest/dev\_guide/developing\_inventory.html#developing-inventory-scripts](https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#developing-inventory-scripts)

Additionally there is a JSON schema file describing the JSON data structure for inventory scripts located at [https://github.com/ansible/ansible/blob/devel/examples/inventory\_script\_schema.json](https://github.com/ansible/ansible/blob/devel/examples/inventory_script_schema.json)

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 9, 2020, 8:53pm UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/3 "2020-06-09T20:53:19Z")

</div>

> ... ideally after prompting the user for this information.  
> ... ask the user for the IP address of the remote server and also the  
> software they want to install?

This is an example of the playbook you might be looking for, I think

&nbsp;&nbsp;- hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: false  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars\_prompt:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "remote\_host"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Enter FQDN or OP of the remote host"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private: no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "pkg"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Enter name of the package"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private: no  
&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- add\_host:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname: "{{ remote\_host }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;groups: my\_group\_01  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sw: "{{ pkg }}"

&nbsp;&nbsp;- hosts: my\_group\_01  
&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: Install {{ sw }} on {{ inventory\_hostname }}

gives

&nbsp;&nbsp;\> ansible-playbook pb.yml  
&nbsp;&nbsp;Enter FQDN or OP of the remote host: test\_01  
&nbsp;&nbsp;Enter name of the package: apache

&nbsp;&nbsp;PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

&nbsp;&nbsp;TASK [add\_host] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;changed: [localhost]

&nbsp;&nbsp;PLAY [my\_group\_01] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

&nbsp;&nbsp;TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;ok: [test\_01]

&nbsp;&nbsp;TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;ok: [test\_01] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"msg": "Install apache on test\_01"  
&nbsp;&nbsp;}

&nbsp;&nbsp;PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;localhost: ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0  
&nbsp;&nbsp;ignored=0  
&nbsp;&nbsp;test\_01 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0  
&nbsp;&nbsp;ignored=0

---

<div class="post-metadata">

**Author:** ![Martin\_Ward](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Martin\_Ward](https://forum.ansible.com/u/Martin_Ward)\
**Post date:** [June 10, 2020, 10:21am UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/4 "2020-06-10T10:21:05Z")

</div>

Thanks Matt, that looks exactly like what I need.

---

<div class="post-metadata">

**Author:** ![Martin\_Ward](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Martin\_Ward](https://forum.ansible.com/u/Martin_Ward)\
**Post date:** [June 10, 2020, 10:48am UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/5 "2020-06-10T10:48:16Z")

</div>

Thanks for the response Vladimir. I had actually found and tried using that code, it works fine for a single prompt but not for two, or at least not where there second input variable is used in a role name. I was after:

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 10, 2020, 12:16pm UTC](https://forum.ansible.com/t/what-does-the-output-from-the-dynamic-inventory-software-look-like/33130/6 "2020-06-10T12:16:36Z")

</div>

> \> - hosts: localhost  
> \> tasks:  
> \> - add\_host:  
> \> hostname: "{{ remote\_host }}"  
> \> groups: my\_group\_01  
> \> sw: "{{ pkg }}"  
> \>  
> \> - hosts: my\_group\_01  
> \> tasks:  
> \> - debug:  
> \> msg: Install {{ sw }} on {{ inventory\_hostname }}

> - hosts: localhost  
> &nbsp;&nbsp;...  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Add remote host to new server list  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add\_host:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ remote\_host }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;groups: server\_list  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> - hosts: server\_list  
> &nbsp;&nbsp;become: True  
> &nbsp;&nbsp;roles:  
> &nbsp;&nbsp;- role: common  
> &nbsp;&nbsp;- role: "{{ pkg }}"
> 
> but it fails with "ERROR! 'pkg' is undefined"

In my example the variable "sw" in the "debug" task works because it was  
declared in the first play's task "add\_host". In your code the variable "pkg"  
is in the "hostvars" of localhost only. See "hostvars"  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#caching-facts](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#caching-facts)
