In this recipe, we will outline how to set up and configure fact caching in Ansible. This is an important feature that can help us in optimizing and speeding the execution time of our playbooks when we require facts to be collected from our infrastructure.
Configuring fact caching in Ansible
How to do it...
- Update the ansible.cfg file to enable fact caching, and set up the required folder to store the cache:
[defaults]
< --- Output Omitted for brevity -->
fact_caching=yaml
fact_caching_connection=./fact_cache
- Create a new pb_get_facts.yml playbook to collect facts from the network using different approaches:
---
- name: Collect Network Facts
hosts: all
tasks:
- name: Collect Facts Using Built-in Fact Modules
...