diff --git a/docs/usage.md b/docs/usage.md index f74ad10..b89ac1d 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -7,6 +7,11 @@ First, generate Ansible output for your hosts: mkdir out ansible -m setup --tree out/ all +In case you want to generate Ansible facts output in your existing +playbooks, you can use/include the +[save_ansible_facts.yml](https://github.com/fboender/ansible-cmdb/blob/master/example/playbooks/save_ansible_facts.yml) +playbook which is provided in the examples. + Next, call ansible-cmdb on the resulting `out/` directory to generate the CMDB overview page: @@ -401,4 +406,3 @@ Generate the overview: ./ansible-cmdb out/ out_custom/ > overview.html The software items will be listed under the "*Custom facts*" heading. - diff --git a/example/playbooks/save_ansible_facts.yml b/example/playbooks/save_ansible_facts.yml new file mode 100644 index 0000000..852b49c --- /dev/null +++ b/example/playbooks/save_ansible_facts.yml @@ -0,0 +1,21 @@ +--- +# .. vim: foldmarker=[[[,]]]:foldmethod=marker + +- name: Save Ansible facts + hosts: [ 'all_managed_hosts' ] + become: False + gather_facts: False + + tasks: + + - name: Write Ansible facts to facts directory + command: ansible -m setup --tree {{ inventory_facts_path|d((inventory_dir | realpath) + "/../../facts") | quote }} {{ inventory_hostname }} --become + become: False + delegate_to: 'localhost' + + - name: Remove often changing facts to make facts deterministic and suitable to be put under version control + shell: jq '{{ inventory_facts_jq_filter|d("del(.ansible_facts.ansible_date_time, .ansible_facts.ansible_env.SUDO_COMMAND, .ansible_facts.ansible_uptime_seconds)") }}' --sort-keys {{ (inventory_hostname) | quote }} > {{ (inventory_hostname + ".tmp") | quote }} && mv {{ (inventory_hostname + ".tmp") | quote }} {{ (inventory_hostname) | quote }}; + args: + chdir: '{{ inventory_facts_path|d((inventory_dir | realpath) + "/../../facts") }}' + become: False + delegate_to: 'localhost'