Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructed inventory #224

Open
gasoo44 opened this issue Oct 20, 2020 · 4 comments
Open

Constructed inventory #224

gasoo44 opened this issue Oct 20, 2020 · 4 comments

Comments

@gasoo44
Copy link

gasoo44 commented Oct 20, 2020

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
Copy link
Owner

fboender commented Sep 4, 2021

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
Copy link

azrdev commented Oct 27, 2021

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
Copy link
Author

gasoo44 commented Oct 29, 2021

@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
Copy link

azrdev commented Oct 30, 2021

Does ansible-cmdb require ini inventories?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants