Skip to content

Commit

Permalink
Add save_ansible_facts.yml playbook for saving facts "in-tree"
Browse files Browse the repository at this point in the history
  • Loading branch information
ypid committed May 21, 2018
1 parent dabc7f8 commit dcc2e98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.

21 changes: 21 additions & 0 deletions example/playbooks/save_ansible_facts.yml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit dcc2e98

Please sign in to comment.