fboender / ansible-cmdb

Generate host overview from ansible fact gathering output
GNU General Public License v3.0
2.36k stars 468 forks source link

Constructed inventory #224

Open gasoo44 opened 4 years ago

gasoo44 commented 4 years ago

It seems that ansible-cmdb does not recognize my constructed inventory file as a dynamic inventory. I followed the example from the ansible website: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html

But when ansible-cmdb runs, it seems to think that the file inventory.config is a static inventory file and does not parse it correctly.

[user@ws ansible]$ ansible -i inventories/hosts.yml -i inventories/inventory.config -m setup --tree tempo/ all
...
[user@ws ansible]$ ansible-cmdb -d -i inventories/hosts.yml -i inventories/inventory.config tempo/ > overview.html
...
Determining type of inventory_path inventories/inventory.config
inventories/inventory.config is a file. Handle as static inventory file
Inventory path inventories/inventory.config is a file. Reading as inventory.
Unsupported vars syntax. Skipping line: plugin: constructed
Unsupported vars syntax. Skipping line: strict: yes

Are constructed inventories not supported or have I made a mistake?

Thanks

fboender commented 3 years ago

Are constructed inventories not supported

It's something I never heard of before to be honest, so I never built any official support in for it.

It looks pretty powerful, so implementing support for this is not going to be easy. Currently ansible-cmdb uses its own host/var/fact parser. That's pretty clumsy, so I want to start using ansible's own parsers. There's a PR request open for that (#215) which I intend to review and merge. However, no garantuees for now that constructed inventories will be supported by that.

Stay tuned...

azrdev commented 3 years ago

as a workaround, you could use ansible-inventory --export --output static.json to dump the original constructed inventory into a "static" variant to pass to ansible-cmdb. Not pretty and probably not performant, though.

gasoo44 commented 3 years ago

@azrdev I tried generating a statiic inventory file as you described. I had to add --list as it is mandatory to add --list, --graph or --host

ansible-inventory -i inventories/hosts.yml -i inventories/inventory.config --export --list --output static.json

As far as I can tell, the resulting json file looks to be valid.

{
    "Group_1": {
        "hosts": [
            "host1",
            "host2",
            "host3"
        ],
        "vars": {
             "var1": "value1",
            "var2": "value2",
            "var3": "Value3"
....cut....

However, ansible-cmdb does throw errors when using the static json file.

ansible-cmdb --template html_fancy_split -d -i static.json tempo/
Determining type of inventory_path static.json
static.json is a file. Handle as static inventory file
Inventory path static.json is a file. Reading as inventory.
Unsupported vars syntax. Skipping line: "Group_1": {
Unsupported vars syntax. Skipping line: "hosts": [
Unsupported vars syntax. Skipping line: "vars": {
...cut....

I also tried with yaml as output but the errors are the same. Does ansible-cmdb require ini inventories?

azrdev commented 3 years ago

Does ansible-cmdb require ini inventories?

@gasoo44 I do think so. Have you tried ansible-inventory --toml ?