fboender / ansible-cmdb

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

ansible-cmdb : 'NoneType' object has no attribute 'get' #59

Closed schms closed 8 years ago

schms commented 8 years ago

a) $ ansible --version ansible 2.0.0.2

$ ansible-cmdb --version ansible-cmdb v1.11

List of hosts: $ ansible -i hosts all --list-hosts hosts (3): client01.example.com client02.example.com opensuse.example.com

b) $ ansible-cmdb -d -i hosts cmdb/ > cmdb.html data_dir = /usr/lib/ansible-cmdb/ansiblecmdb/data tpl_dir = /usr/lib/ansible-cmdb/ansiblecmdb/data/tpl static_dir = /usr/lib/ansible-cmdb/ansiblecmdb/data/static Parsing fact dir: cmdb/ Reading host facts from cmdb/client02.example.com Reading host facts from cmdb/opensuse.example.com Reading host facts from cmdb/client01.example.com Parsing host vars (dir): hosts template file = /usr/lib/ansible-cmdb/ansiblecmdb/data/tpl/html_fancy.tpl Template params: {'lib_dir': '/usr/lib/ansible-cmdb/ansiblecmdb/data', 'version': '1.11', 'data_dir': '/usr/lib/ansible-cmdb/ansiblecmdb/data', 'log': <logging.RootLogger object at 0x7f114ab72250>, 'columns': None} Rendering host overview for opensuse.example.com Rendering host overview for client02.example.com Rendering host overview for client01.example.com

Traceback (most recent call last): File "/usr/bin/ansible-cmdb", line 108, in out = mytemplate.render(hosts=ansible.hosts, _params) File "/usr/lib/ansible-cmdb/mako/template.py", line 443, in render return runtime.render(self, self.callable, args, data) File "/usr/lib/ansible-cmdb/mako/runtime.py", line 803, in _render __kwargs_forcallable(callable, data)) File "/usr/lib/ansible-cmdb/mako/runtime.py", line 835, in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File "/usr/lib/ansible-cmdb/mako/runtime.py", line 860, in _exectemplate callable(context, _args, *_kwargs) File "/usr/lib/ansible-cmdb/ansiblecmdb/data/tpl/html_fancy.tpl", line 487, in render_body

${col["func"](host)}

File "/usr/lib/ansible-cmdb/ansiblecmdb/data/tpl/html_fancy.tpl", line 0, in col_dtap

File "/usr/lib/ansible-cmdb/ansiblecmdb/data/tpl/html_fancy.tpl", line 44, in render_col_dtap ${host['hostvars'].get('dtap', '')} AttributeError: 'NoneType' object has no attribute 'get'

Whoops, it looks like something went wrong while rendering the template.

The reported error was: 'NoneType' object has no attribute 'get'

The output is probably not correct. You can report a bug on the issue tracker:

https://github.com/fboender/ansible-cmdb/issues

Please include the debugging output (-d switch) in the report! /data/ansible$

schms commented 8 years ago

Sorry, I can not help a lot as I am not a programmer. However, Does ansible-cmdb support ansible 2.x ?

fboender commented 8 years ago

Hey schms!

Thank you for reporting the bug. Do you have enough experience to try the lastest version of Ansible-cmdb from the Github repository? I suspect this bug may have already been fixed. Otherwise, could you send the facts file for client01.example.com to my email address? (ferry.boender@gmail.com).

Ansible-cmdb should support ansible v2.x, but since it's rather new, there may still be some bugs in it. This could be one.

Regards,

Ferry

schms commented 8 years ago

Hi Ferry

It looks rather good. What I did: a) Collect the facts in /tmp/out/ : foo@baa:/data/ansible$ ansible -i hosts all -m setup --tree /tmp/out/

Check out latest commit (?) : foo@baa:/tmp$ git clone https://github.com/fboender/ansible-cmdb.git Cloning into 'ansible-cmdb'...

foo@baa:/tmp$ cd ansible-cmdb/

foo@baa:/tmp/ansible-cmdb$ git log commit e18c52f534e0084e12fb7b257ac3069b242a367b Author: Ferry Boender ferry.boender@gmail.com Date: Tue Feb 2 08:25:25 2016 +0100

Example openvz host added.

foo@baa:/tmp/ansible-cmdb$ export PYTHONPATH="$(readlink -f lib)"

This works: foo@baa:/tmp/ansible-cmdb$ src/ansible-cmdb /tmp/out/ > /tmp/overview10.hmtl

This works as well: foo@baa:/tmp/ansible-cmdb$ src/ansible-cmdb -t txt_table /tmp/out/ > /tmp/overview11.hmtl

However, finally I wanted to include the Ansible inventory file </data/ansible/hosts>. This still fails: (..) foo@baa:/tmp/ansible-cmdb$ src/ansible-cmdb -d -i /data/ansible/hosts /tmp/out/ > /tmp/overview12.hmtl data_dir = /tmp/ansible-cmdb/src/ansiblecmdb/data tpl_dir = /tmp/ansible-cmdb/src/ansiblecmdb/data/tpl static_dir = /tmp/ansible-cmdb/src/ansiblecmdb/data/static Parsing fact dir: /tmp/out/ Reading host facts from /tmp/out/client02.example.com Reading host facts from /tmp/out/opensuse.example.com Reading host facts from /tmp/out/client01.example.com Parsing host vars (dir): /data/ansible/hosts template file = /tmp/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy.tpl Template params: {'lib_dir': '/tmp/ansible-cmdb/src/ansiblecmdb/data', 'version': '%%MASTER%%', 'data_dir': '/tmp/ansible-cmdb/src/ansiblecmdb/data', 'log': <logging.RootLogger object at 0x7f0e95f5c1d0>, 'columns': None} Rendering host overview for opensuse.example.com Rendering host overview for client02.example.com Rendering host overview for client01.example.com

Traceback (most recent call last): File "src/ansible-cmdb", line 108, in out = mytemplate.render(hosts=ansible.hosts, _params) File "/tmp/ansible-cmdb/lib/mako/template.py", line 443, in render return runtime.render(self, self.callable, args, data) File "/tmp/ansible-cmdb/lib/mako/runtime.py", line 803, in _render __kwargs_forcallable(callable, data)) File "/tmp/ansible-cmdb/lib/mako/runtime.py", line 835, in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File "/tmp/ansible-cmdb/lib/mako/runtime.py", line 860, in _exectemplate callable(context, _args, *_kwargs) File "/tmp/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy.tpl", line 503, in render_body

${col["func"](host)}

File "/tmp/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy.tpl", line 0, in col_dtap

File "/tmp/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy.tpl", line 44, in render_col_dtap ${host['hostvars'].get('dtap', '')} AttributeError: 'NoneType' object has no attribute 'get'

Whoops, it looks like something went wrong while rendering the template.

The reported error was: 'NoneType' object has no attribute 'get'

The output is probably not correct. You can report a bug on the issue tracker:

https://github.com/fboender/ansible-cmdb/issues

Please include the debugging output (-d switch) in the report! foo@baa:/tmp/ansible-cmdb$

(..)

Nevertheless, thank you very much for ansible-cmdb. Great work !

Regards

Stefan

fboender commented 8 years ago

Hey Stefan!

Thank you for trying that out. Could you send the contents of the client01.example.com facts file to ferry.boender@gmail.com, so I can have a look at what's going wrong? It seems there is no "hostvars" section. I'll keep it strictly confidential.

Regards,

Ferry

fboender commented 8 years ago

Oh, can you also include your hosts file? The problem might also be in there.

schms commented 8 years ago

Hi Ferry, I am having trouble sending you the contents of client01.example.com facts and the hosts file as gmail.com seems to reject the mail(s):

(..) ferry.boender@gmail.com: SMTP error from remote server for TEXT command, host: gmail-smtp-in.l.google.com (173.194.65.26) reason: 552-5.7.0 This message was blocked because its content presents a potential security issue (..)

schms commented 8 years ago

The hosts file:

[common] client01.example.com client02.example.com opensuse.example.com

schms commented 8 years ago

The facts of client01.example.com:

{"ansible_facts": {"ansible_all_ipv4_addresses": ["192.168.0.90"], "ansible_all_ipv6_addresses": ["fe80::a00:27ff:fea8:34c3"], "ansible_architecture": "i386", "ansible_bios_date": "12/01/2006", "ansible_bios_version": "VirtualBox", "ansible_cmdline": {"BOOT_IMAGE": "/boot/vmlinuz-3.16.7-29-default", "quiet": true, "resume": "/dev/sda1", "root": "UUID=b77dc505-6528-4b8b-8942-f4f6a48d702c", "showopts": true, "splash": "silent"}, "ansible_date_time": {"date": "2016-02-10", "day": "10", "epoch": "1455127949", "hour": "19", "iso8601": "2016-02-10T18:12:29Z", "iso8601_basic": "20160210T191229207737", "iso8601_basic_short": "20160210T191229", "iso8601_micro": "2016-02-10T18:12:29.207985Z", "minute": "12", "month": "02", "second": "29", "time": "19:12:29", "tz": "CET", "tz_offset": "+0100", "weekday": "Wednesday", "weekday_number": "3", "weeknumber": "06", "year": "2016"}, "ansible_default_ipv4": {"address": "192.168.0.90", "alias": "enp0s3", "broadcast": "192.168.0.255", "gateway": "192.168.0.1", "interface": "enp0s3", "macaddress": "08:00:27:a8:34:c3", "mtu": 1500, "netmask": "255.255.255.0", "network": "192.168.0.0", "type": "ether"}, "ansible_default_ipv6": {}, "ansible_devices": {"sda": {"holders": [], "host": "SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode](rev 02)", "model": "VBOX HARDDISK", "partitions": {"sda1": {"sectors": "1523712", "sectorsize": 512, "size": "744.00 MB", "start": "2048"}, "sda2": {"sectors": "15251456", "sectorsize": 512, "size": "7.27 GB", "start": "1525760"}}, "removable": "0", "rotational": "1", "scheduler_mode": "cfq", "sectors": "16777216", "sectorsize": "512", "size": "8.00 GB", "support_discard": "0", "vendor": "ATA"}, "sr0": {"holders": [], "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", "model": "CD-ROM", "partitions": {}, "removable": "1", "rotational": "1", "scheduler_mode": "cfq", "sectors": "139264", "sectorsize": "2048", "size": "272.00 MB", "support_discard": "0", "vendor": "VBOX"}}, "ansible_distribution": "openSUSE", "ansible_distribution_major_version": "13", "ansible_distribution_release": "Harlequin", "ansible_distribution_version": "13.2", "ansible_dns": {"nameservers": ["62.2.17.60"], "search": ["example.com"]}, "ansible_domain": "", "ansible_enp0s3": {"active": true, "device": "enp0s3", "ipv4": {"address": "192.168.0.90", "broadcast": "192.168.0.255", "netmask": "255.255.255.0", "network": "192.168.0.0"}, "ipv6": [{"address": "fe80::a00:27ff:fea8:34c3", "prefix": "64", "scope": "link"}], "macaddress": "08:00:27:a8:34:c3", "module": "e1000", "mtu": 1500, "pciid": "0000:00:03.0", "promisc": false, "type": "ether"}, "ansible_env": {"ALSA_CONFIG_PATH": "/etc/alsa-pulse.conf", "AUDIODRIVER": "pulseaudio", "COLORTERM": "1", "CONFIG_SITE": "/usr/share/site/i686-pc-linux-gnu", "CPU": "i686", "CSHEDIT": "emacs", "CVS_RSH": "ssh", "FROM_HEADER": "", "GPG_TTY": "/dev/pts/0", "G_BROKEN_FILENAMES": "1", "G_FILENAME_ENCODING": "@locale,UTF-8,ISO-8859-15,CP1252", "HISTSIZE": "1000", "HOME": "/home/stefan", "HOST": "client01", "HOSTNAME": "client01", "HOSTTYPE": "i386", "INPUTRC": "/home/stefan/.inputrc", "JAVA_BINDIR": "/usr/lib/jvm/jre/bin", "JAVA_HOME": "/usr/lib/jvm/jre", "JAVA_ROOT": "/usr/lib/jvm/jre", "JRE_HOME": "/usr/lib/jvm/jre", "LANG": "C", "LC_ADDRESS": "de_CH.UTF-8", "LC_ALL": "C", "LC_IDENTIFICATION": "de_CH.UTF-8", "LC_MEASUREMENT": "de_CH.UTF-8", "LC_MESSAGES": "C", "LC_MONETARY": "de_CH.UTF-8", "LC_NAME": "de_CH.UTF-8", "LC_NUMERIC": "de_CH.UTF-8", "LC_PAPER": "de_CH.UTF-8", "LC_TELEPHONE": "de_CH.UTF-8", "LC_TIME": "de_CH.UTF-8", "LESS": "-M -I -R", "LESSCLOSE": "lessclose.sh %s %s", "LESSKEY": "/etc/lesskey.bin", "LESSOPEN": "lessopen.sh %s", "LESS_ADVANCED_PREPROCESSOR": "no", "LIBGL_DEBUG": "quiet", "LOGNAME": "stefan", "MACHTYPE": "i686-suse-linux", "MAIL": "/var/mail/stefan", "MANPATH": "/usr/local/man:/usr/share/man", "MINICOM": "-c on", "MORE": "-sl", "NNTPSERVER": "news", "NO_AT_BRIDGE": "1", "OSTYPE": "linux", "PAGER": "less", "PATH": "/home/stefan/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games", "PROFILEREAD": "true", "PWD": "/home/stefan", "PYTHONSTARTUP": "/etc/pythonstart", "QEMU_AUDIO_DRV": "pa", "QT_SYSTEM_DIR": "/usr/share/desktop-data", "SDL_AUDIODRIVER": "pulse", "SHELL": "/bin/bash", "SHLVL": "1", "SSH_CLIENT": "192.168.0.12 37777 22", "SSH_CONNECTION": "192.168.0.12 37777 192.168.0.90 22", "SSH_SENDS_LOCALE": "yes", "SSH_TTY": "/dev/pts/0", "TERM": "xterm", "USER": "stefan", "WINDOWMANAGER": "/usr/bin/startkde", "XCURSOR_THEME": "DMZ", "XDG_CONFIG_DIRS": "/etc/xdg", "XDG_DATA_DIRS": "/usr/share", "XDG_RUNTIME_DIR": "/run/user/1000", "XDG_SESSIONID": "2", "XKEYSYMDB": "/usr/X11R6/lib/X11/XKeysymDB", "XNLSPATH": "/usr/share/X11/nls", "": "/usr/bin/python"}, "ansible_fips": false, "ansible_form_factor": "Other", "ansible_fqdn": "client01", "ansible_hostname": "client01", "ansible_interfaces": ["lo", "enp0s3"], "ansible_kernel": "3.16.7-29-default", "ansible_lo": {"active": true, "device": "lo", "ipv4": {"address": "127.0.0.1", "broadcast": "host", "netmask": "255.0.0.0", "network": "127.0.0.0"}, "ipv6": [{"address": "::1", "prefix": "128", "scope": "host"}], "mtu": 65536, "promisc": false, "type": "loopback"}, "ansible_local": {"group_oracle": {"name": "oracle"}}, "ansible_lsb": {"codename": "Harlequin", "description": "openSUSE 13.2 (Harlequin) (i586)", "id": "openSUSE project", "major_release": "13", "release": "13.2"}, "ansible_machine": "i686", "ansible_machine_id": "41682fecf107478b8c4e3a127b7581e9", "ansible_memfree_mb": 217, "ansible_memory_mb": {"nocache": {"free": 335, "used": 49}, "real": {"free": 217, "total": 384, "used": 167}, "swap": {"cached": 0, "free": 743, "total": 743, "used": 0}}, "ansible_memtotal_mb": 384, "ansible_mounts": [{"device": "/dev/sda2", "fstype": "btrfs", "mount": "/", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/tmp", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/spool", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/opt", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/lib/pgsql", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/lib/named", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/lib/mailman", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/usr/local", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/crash", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/tmp", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/srv", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/opt", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/home", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/boot/grub2/i386-pc", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}, {"device": "/dev/sda2", "fstype": "btrfs", "mount": "/var/log", "options": "rw,relatime,space_cache", "size_available": 1106178048, "size_total": 7808745472, "uuid": ""}], "ansible_nodename": "client01", "ansible_os_family": "Suse", "ansible_pkg_mgr": "zypper", "ansible_processor": ["GenuineIntel", "Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz"], "ansible_processor_cores": 1, "ansible_processor_count": 1, "ansible_processor_threads_per_core": 1, "ansible_processor_vcpus": 1, "ansible_product_name": "VirtualBox", "ansible_product_serial": "NA", "ansible_product_uuid": "NA", "ansible_product_version": "1.2", "ansible_python_version": "2.7.8", "ansible_selinux": false, "ansible_service_mgr": "systemd", "ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAJY+qApSzP40Acl+pwETuodju3bTUtw8IXEx2Q2DydQRHyLS0MR7IFkRWon+s2WNlYBpAJJhb4IM/eByj4ttqX4fxyUGLkXWzeph39PnSb1nVu/73x39HMp504TYpGQ3rWc9TkB9Pp2VJjUwG9lbIUNZ4ZLnEzxycB6hNAFN4etxAAAAFQCNcpsfSjqyUmGQutYJgNx5B5OIYwAAAIB3u8mJc/EdIpums2AyCgrj24F4/wqhsHF9Q6/snGYXJmFBiMt91/LjpxFJPdrueRsEVsMY66zHfJlelFA4xs6BZp1Ue5wqSDJ6F3hMIqrwuksvi80Eo68EjtERbBaAUqO2CEUOJAeqaXauPI3mdJrm5EJigdWX0z3rjyIZeVXSRQAAAIAfDPG4/PmBDTzKtPE0otRvoVLFiqFQn751gf6NpYzCMF/0JtE035yZ4GAANm1buAvPSqxasZVETlvkmS5cJEzzpf3tCVmcDfV1mXyqK7IYPLRwHK25LKkvodxZFAmO64lZLix9/K/QlI6uE9rgXP3vUGnNUcSXKm+ZHzVw0IEiNQ==", "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJBglouLdnW7YehKAtrOMjl/Wp6NsPM0/32LPkuYMGefqL9mQCPrPUua7cJ79H1r/SVLcCr7KqkMKsMIFK9MvNk=", "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIFnzGlNCwkR11IFSdNtdbi2+5TBNAoSi0Y6xvIknb2TR", "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDO796ovxhfkSc1Oyqhcllu8u6iAC2VRU0BnMqsGETnRQRVBb5YQexn8jFm5nbsjlvOCijIII5HCr3Hh+A9e8JQxYr6SqTOa4wTwVByDbkWwYJ9nwj7JmMV0pPcbE6wid0op/2A71rR6jTdqEssk1yMvI3ggXsZvYibhtZmDSg9YPZA+R5SIR2zejC9KJuMxu6IBmxgG5GUPphzbbQcA+dcnOJQgilr+MxpPDE+R+KHsH9ITlFv6rFfZ9PV8QMw71DDGvr8qVnbr/I+Qtm9M2J6x2PF9J4JX+2BDidBtTngjmnw9mNV5ko/8EZge56hVh7ZslwEVknnf9nDxRyQcown", "ansible_swapfree_mb": 743, "ansible_swaptotal_mb": 743, "ansible_system": "Linux", "ansible_system_vendor": "innotek GmbH", "ansible_uptime_seconds": 439, "ansible_user_dir": "/home/stefan", "ansible_user_gecos": "Stefan Schmid", "ansible_user_gid": 100, "ansible_user_id": "stefan", "ansible_user_shell": "/bin/bash", "ansible_user_uid": 1000, "ansible_userspace_architecture": "i386", "ansible_userspace_bits": "32", "ansible_virtualization_role": "guest", "ansible_virtualization_type": "virtualbox", "module_setup": true}, "changed": false}

fboender commented 8 years ago

Thank you for providing the information Stefan.

When I run ansible-cmdb v1.11 with the data you provided I get a different error:

$ ansible-cmdb -i ../example/hosts ../example/out > /dev/null
Error parsing: .invalid_file: No JSON object could be decoded

When I run it again with the latest version (master), it seems to work:

ansible-cmdb/src (master) * $ ./ansible-cmdb -i ../example/hosts ../example/out > /dev/null
ansible-cmdb/src (master) * $

It's possible I've fixed this issue between v1.11 and the latest version in Git. Can you check if it works with the latest version? Instruction for how to do that can be found here: https://github.com/fboender/ansible-cmdb#running-from-the-git-repo

fboender commented 8 years ago

Any news on if this issue has been fixed?