ansible-cmdb icon indicating copy to clipboard operation
ansible-cmdb copied to clipboard

exception dynamic inventory when subfolders

Open Anasme opened this issue 5 years ago • 5 comments

Hello,

I'm trying ansible-cmdb and it seem very nice, thank you. Unfortunately I encounter an error when reading my inventory:

[root@server:~]# ansible-cmdb -i /etc/ansible/inventories/prod out/ > overview.html Exception while executing dynamic inventory script '/etc/ansible/inventories/prod/hosts': [Errno 8] Exec format error Traceback (most recent call last): File "/usr/local/bin/../lib/ansiblecmdb/ansible-cmdb.py", line 205, in limit=options.limit, debug=options.debug) File "/usr/local/lib/python2.7/dist-packages/ansiblecmdb/ansible.py", line 61, in init self._parse_hostvar_dir(inventory_path) File "/usr/local/lib/python2.7/dist-packages/ansiblecmdb/ansible.py", line 188, in _parse_hostvar_dir self._parse_hostvar_file(hostname, p) File "/usr/local/lib/python2.7/dist-packages/ansiblecmdb/ansible.py", line 196, in _parse_hostvar_file first_line = open(path, 'r').readline() IOError: [Errno 21] Is a directory: '/etc/ansible/inventories/prod/host_vars/FQDN/vault'

my inventories tree look like this (exemple of course): in host_vars I have some server with 2 subfolders like ./server/vars ./server/vault

. ├── group_vars │   ├── all │   │   └── 000_cross_env_vars -> ../../../000_cross_env_vars │   ├── prod_censored_ab │   │   ├── dns.yml │   │   └── censored.yml │   ├── prod_censored_am_expert │   │   ├── parameters.yml │   │   └── censored.yml │   ├── prod_censored_am_pro │   │   ├── dns.yml │   │   ├── document.yml │   │   ├── nginx_vhosts.yml │   │   ├── parameters.yml │   │   └── censored.yml │   ├── prod_censored_xyxyx │   │   └── document.yml │   ├── prod_censored_xyxyxy │   │   └── censored.yml │   ├── prod_censored_xyxy │   │   └── censored.yml │   ├── prod_censored_xyx │   │   ├── document.yml │   │   └── censored.yml │   ├── prod_censored_yy │   │   ├── document.yml │   │   └── censored.yml │   ├── prod_censored_x │   │   └── censored.yml │   ├── prod_censored_xy │   │   ├── dns.yml │   │   └── censored.yml │   ├── prod_soft_gitlab │   │   └── dns.yml │   └── prod_soft_vc │   ├── dns.yml │   └── nginx.yml ├── hosts └── host_vars ├── server1 │   ├── vars │   └── vault ├── server2 │   ├── censored.yml │   └── vault ├── server3 │   ├── dns.yml │   ├── document.yml │   ├── nginx.yml │   ├── censored.yml │   └── vault ├── server4 │   ├── vars │   └── vault ├── server5 │   ├── vars │   └── vault ├── server6 │   ├── vars │   └── vault ├── server7 │   ├── vars │   └── vault ├── server8 │   ├── vars │   └── vault

I want to create a cmdb with your tools to retrieve the basic information that you propose, add all the variables by groups/hosts and some additional facts that I could automate (apache version, tomcat etc.)

Thank a lot for your future help

Anasme avatar Apr 05 '19 10:04 Anasme

Hi Anasme!

I'm not sure, but it looks like you're specifying a path to a directory for the -i param, instead of pointing it to the hosts file. If you point -i to the hosts file as shown in your directory listing, it will automatically pick up the group_vars and host_vars dirs in that same dir.

Can you try something like?:

ansible-cmdb -i /etc/ansible/inventories/prod/hosts out/ > overview.html

If that still gives errors, let me know, and I can look into it.

fboender avatar Apr 06 '19 07:04 fboender

Confirmed that this is a bug in ansible-cmdb.

fboender avatar Apr 07 '19 18:04 fboender

For now I've "fixed" this by skipping directories in host_vars. Not really a fix, but I'm reworking the parsing of host/group vars and don't want to invest time in properly parsing the myriad of exceptions and hidden features in Ansible inventories in the old code.

fboender avatar Apr 07 '19 18:04 fboender

For now I've "fixed" this by skipping directories in host_vars. Not really a fix, but I'm reworking the parsing of host/group vars and don't want to invest time in properly parsing the myriad of exceptions and hidden features in Ansible inventories in the old code.

Hey ! Thank for your reply. Nice to hear you are reworking this part :), I will wait for it, I'm on another project atm. I stay tunned !

Anasme avatar Apr 09 '19 09:04 Anasme

hey @fboender , how are you? what's new on the redesign of your ansible-cmdb?

Anasme avatar May 27 '19 12:05 Anasme