Dynamic inventory json format question

143 views
Skip to first unread message

fseu...@gmail.com

unread,
Apr 18, 2018, 2:34:56 AM4/18/18
to Ansible Project
Hello,

in the past i used this inventory entries.

inventory.ini format:

[DATABASE1]
hostname1.com

[DATABASE2]
hostname47.de

dynamic inventory json format:
{
  "DATABASE1" : { "hosts" : [  "hostname1.com ] },
  "DATABASE2" : { "hosts" : [ "hostname47.de ] }
}

This setup wors fine.

For internal reasons i have to cahneg the format.
Here is a example that works for me as i expect in inventory.ini format:

[DATABASE1]
DATABASE1_hostname1.com  ansible_host=hostname1.com

[DATABASE2]
DATABASE_2_hostname47.de ansible_host=hostname47.de

Can please someone give me the eqivalent json format?

Many thanks
Frank

Matt Martz

unread,
Apr 18, 2018, 10:08:45 AM4/18/18
to ansible...@googlegroups.com
My recommendation, is to use the ansible-inventory command to show you what the output should look like:

ansible-inventory -i inventory.ini --list

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/291e84fc-e3ca-43a6-a453-bb4fc0a72aef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
Apr 18, 2018, 2:08:44 PM4/18/18
to Ansible Project
for recreating an inventory: ansible-inventory -i inventory.ini --list
--export, w/o the --export it just shows a 'flattened view' which is
what ansible sees internally, good for debugging but not for emulating
in your own inventory source.


--
----------
Brian Coca

fseu...@gmail.com

unread,
Apr 19, 2018, 2:05:25 AM4/19/18
to Ansible Project
Hello,

i did a ansible-inventory -i inventory.ini --list  against my working inventory.ini and got the following result:

$ ansible-inventory -i inventory.ini --list
 [WARNING]:  * Failed to parse /APPL/ansible/cfg/inventory.ini with ini plugin: /APPL/ansible/cfg/inventory.ini:2: Expected key=value host variable assignment, got: :
 [WARNING]: Unable to parse /APPL/ansible/cfg/inventory.ini as an inventory source
 [WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {
            "{": {
                "ansible_ssh_pass": "xxx",
                "ansible_user": "oracle"
            }
        }
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    },
    "ungrouped": {
        "hosts": [
            "{"
        ]
    }
}

So i still do not know how the the json format should be....
Frank

lambd...@yahoo.com

unread,
Apr 19, 2018, 2:56:36 AM4/19/18
to Ansible Project
Hi

Can you post contents of your inventory.ini

fseu...@gmail.com

unread,
Apr 19, 2018, 10:03:06 AM4/19/18
to Ansible Project
Hello,
as i did in my question - but here again:


[DATABASE1]
DATABASE1_hostname1.com  ansible_host=hostname1.com

[DATABASE2]
DATABASE_2_hostname47.de ansible_host=hostname47.de

fseu...@gmail.com

unread,
Apr 19, 2018, 10:16:28 AM4/19/18
to Ansible Project

Hello,

ansible-inventory -i inventory.ini --list  worked now fine for me.
(I had a typo in the inventory.ini which prevented ansible-Inventory .... --list from working in the correct way).
Many tnaks for all your help!
Frank

Reply all
Reply to author
Forward
0 new messages