Ansible doesn't actually have anywhere you can store your server facts. But at the same time, you have a wealth of information at your fingertips because of Ansible, you just can't get to it very quickly.
This Demo covers:
• Set up a DB to collect our server facts.
• Download the AnsibleDB_collection, configure it and collect the facts.
• The ansible collection will push the facts into the DB.
• Once we have the data stored, I’ll show you how to pull it out using ./JQ.
• Extend fact collection to custom facts like AWS metadata
• It’s a powerful data store for server facts.
• Works for Linux, Windows, network devices, storage device and more
No privileged access required.
This is an open-source project I've been working on with a colleague.
Links:
AnsibleDB database:
https://github.com/apidb-io/ansibledb...
Ansibledb collection:
https://galaxy.ansible.com/apidb/ansi...
Custom extensions:
https://github.com/apidb-io/custom_ex...
Here are some ./JQ examples to get you started:
--### Without Custom Extensions ###--
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_os_family) | map({(.[0].ansible_facts.ansible_os_family):length})"
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_distribution_version) | map({(.[0].ansible_facts.ansible_distribution_version):length})"
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_os_family) | map({(.[0].ansible_facts.ansible_os_family):length})"
--### With Custom Extensions ###--
curl -sk https://IP_ADDRESS_OF_DB/api/servers | jq -r '.[].ansible_facts.ansible_local.local'
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_local.local.local_facts.avail_zone) | map({(.[0].ansible_facts.ansible_local.local.local_facts.avail_zone):length})"
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_local.local.local_facts.cloud) | map({(.[0].ansible_facts.ansible_local.local.local_facts.cloud):length})"
curl -sk https://3.8.151.155/api/servers | jq 'group_by(.ansible_facts.ansible_local.local.local_facts.instance_type) | map({region: map(.ansible_facts.ansible_local.local.local_facts.avail_zone) | unique, (.[0].ansible_facts.ansible_local.local.local_facts.instance_type): map(.ansible_facts.ansible_local.local.local_facts.instance_type) | length})'
curl -sk https://3.8.151.155/api/servers | jq "group_by(.ansible_facts.ansible_local.local.local_facts.instance_type) | map({(.[0].ansible_facts.ansible_local.local.local_facts.instance_type):length})"
Watch video Ansible: How to collect and store server facts - ansibledb online without registration, duration hours minute second in high quality. This video was added by user LondonIAC / Dennis McCarthy / Automation Engineer 08 May 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,842 once and liked it 26 people.