fboender / ansible-cmdb

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

host local facts not added to sql table. #106

Closed jab2805rakuten closed 7 years ago

jab2805rakuten commented 7 years ago

Hi

I love the fact that Host local facts get added to the fancy html. How can a get them also added to sql or csv templates? For some reason the setup module does not list vm on a hypervisor so I added local host facts.

All my steps below

Steps:

  1. Run the setup on the group of servers

ansible -m setup --tree 10.133.12.0/ 10.133.12.0-200

  1. Create the fancy html that has the data:

ansible-cmdb 10.133.12.0/ > /var/www/html/inventory/10.131.12.0-200.html

Steps SQL:

  1. Create SQL data:

ansible-cmdb -t sql -i 10.133.12.0-200 out > cmdb.sql

  1. Look at sql data:

    mysql -uroot -p ansiblecmdb < cmdb.sql

The Host local facts are not in the database?

=================================================

Steps to create local facts on remote KVM server:

shell commands: mkdir /etc/ansible/facts.d mkdir -p /etc/ansible/facts.d cp virtlst.py /etc/ansible/facts.d/virtlst.fact chmod 755 /etc/ansible/facts.d/virtlst.fact

Script:

cat virtlst.py

=========================================

!/usr/bin/python

from subprocess import * import json

b = Popen(["virsh", "list", "--all"], stdout=PIPE)

out = b.stdout.read()

each_virt = [] out_lines = out.strip().split("\n")[2:-1] for lines in out_lines: v = lines.split()[1] each_virt.append(v) my_dict = { 'virts': each_virt } print json.dumps(my_dict)

================================================

Run

./virtlst.py

================================================ {"virts": ["va-openstackallinone-01-ops-vm-tr", "va-zenoss-01-ops-vm-tr-clone", "va-zabbix-01-ops-vm-tr"]}


fboender commented 7 years ago

Hi jab2805rakuten!

Thanks for the feature request. The problem with including host local facts in CSV or SQL files is that the facts are user-defined. As such there's no way to know which items are going to be present. The reason they can be included in the HTML template is because there we don't have to care about the structure of the user-defined data, whereas in the CSV or SQL file, it has to follow strict rules about which kind of data we can include (columnar data, basically).

I see no way to properly include host local facts in such a way that would be beneficial for all users of Ansible-cmdb. I recommend taking a look at the templates to see if you can add the information you want to the SQL or CSV template yourself, for you specific case.

With kind regards,

Ferry