Hello,
I am running into a problem with trying to create Dynamic Inventories via a Python Script, when the structure has Groups that belong to Groups.
If I just have a list of servers in each group, I do not have any problems.
Here is an INI example of what I need to create:
For example, here is what the INI version of my inventory would look likeL
[cell_test_1]
unix1
unix9
[cell_test_2]
unix2
unix10
[Test:children]
cell_test_1
cell_test_2
My script is able to generate either yaml or jason.
The output or each look like:
YAML
Test:
children:
cell_test_1:
hosts:
- unix1
- unix9
cell_test_2:
hosts: - unix2
- unix10
JSON{“test”: {“children”: {“cell_test_1”: {“hosts”: [“unix1”, “unix9”]}, “cell_test_2”: {“hosts”: [“unix2”, “unix10”]}}, “vars”: null}}
Feeding in either into Tower produces the output of:
2.060 INFO Updating inventory 94: xx_Test_Inventory
2
2.112 DEBUG Using system install of ansible-inventory CLI: /usr/bin/ansible-inventory
3
2.112 INFO Reading Ansible inventory source: /tmp/awx_45115_aZ12p6/tmpYrrkcr
4
2.123 DEBUG Using provided directory ‘/tmp/awx_45115_aZ12p6’ for isolation.
5
2.123 DEBUG Running from /tmp/awx_45115_aZ12p6
working directory.
6
3.154 INFO Processing JSON output…
7
3.154 DEBUG Loaded group: all
8
3.154 DEBUG Loaded group: Test
9
3.155 DEBUG Adding child group Test to parent all
10
3.155 DEBUG Loaded group: cell_test_1
11
3.155 DEBUG Adding child group cell_test_1 to parent Test
12
3.155 DEBUG Loaded group: cell_test_2
13
3.155 DEBUG Adding child group cell_test_2 to parent Test
14
3.155 DEBUG Adding child group Test to parent all
15
3.155 DEBUG Adding child group Test to parent all
16
3.155 DEBUG Finished loading from source: /tmp/awx_45115_aZ12p6/tmpYrrkcr
17
3.156 DEBUG Removing empty group cell_test_1
18
3.156 DEBUG Removing empty group cell_test_2
19
3.156 INFO Loaded 1 groups, 0 hosts
20
3.324 DEBUG Group “test” deleted
21
3.330 DEBUG Inventory variables unmodified
22
3.364 DEBUG Group “Test” added
23
3.485 INFO Inventory import completed for AJ_Test_WAS_Inventory in 1.4s
Has anyone else run into this problem?
Can I get help as to what either format (YAML or JSON) should look like to get the hosts to be added to the cell_test_* groups?
Thanks much!