--limit.
Overview
Fact caching is configurable on a per-job-template basis. When enabled, AWX serves fact requests for all hosts in an inventory related to the running job.This allows users to use Job Templates with
--limit while still having access to the entire Inventory of host facts.How It Works
Fact Cache Implementation
Fact Injection
When a job launches with
use_fact_cache=True, AWX writes all ansible_facts associated with each host in the inventory as JSON files on the local file system (one file per host)Ansible Plugin Usage
Ansible is configured to use the
jsonfile cache plugin:get()calls result in JSON file lookups for host-specific factsset()calls write JSON files to the local file system
Configuration
Enabling Fact Cache on Job Templates
Enable fact caching when creating or updating a Job Template:- Navigate to Job Templates
- Edit the desired template
- Enable “Enable Fact Storage”
- Save the template
Fact Cache Timeout
Configure the global fact cache timeout in AWX settings:Facts older than the timeout will not be used from the cache and must be re-gathered.
Use Cases
Limited Host Operations
Run playbooks against a subset of hosts while maintaining access to all inventory facts:Multi-Tier Applications
Share facts between different tiers:
All templates use the same inventory and have
use_fact_cache=True.
Performance Optimization
Skip redundant fact gathering:With fact caching enabled, you can set
gather_facts: no to skip the gathering phase and use cached facts, significantly reducing playbook run time.Fact Cache Behavior
When Facts Are Written
Facts are written to the cache:- When a playbook runs with
gather_facts: yes(default) - When using the
setupmodule explicitly - When using the
set_statsmodule (for custom facts) - When fact cache is enabled on the Job Template
use_fact_cache=False:
- Will NOT write ansible_facts files
- Will NOT update the fact cache
- Cannot access cached facts from other jobs
When Facts Are Read
Facts are read from the cache:- At the start of job execution (if enabled)
- Only facts newer than
ANSIBLE_FACT_CACHE_TIMEOUT - For all hosts in the inventory, not just hosts in the play
Fact Invalidation
Fact Logging
New and changed facts are logged via AWX’s logging facility. Log Namespace:system_tracking
Log Payload Includes:
host_name- Name of the hostinventory_id- ID of the inventoryansible_facts- Dictionary of all Ansible facts
Managing Facts
Viewing Host Facts
Access facts via the API:- Navigate to Inventories
- Select an inventory
- Click on Hosts
- Select a host
- View the “Facts” tab
Clearing Facts
Clear facts for a specific host:The
clear_facts endpoint sets hosts/<id>/ansible_facts to {}.Preventing Fact Clearing
Integration with Workflows
Fact caching works seamlessly with workflows:Custom Facts
Store custom facts usingset_stats:
Performance Considerations
Faster Playbooks
Skip fact gathering when using cached facts to reduce playbook run time by 5-30 seconds per host
Reduced Load
Fewer SSH connections and fact gathering operations reduce load on managed hosts
Network Efficiency
Less data transfer when facts are served from cache instead of gathering
Scalability
Large inventories benefit significantly from fact caching
Troubleshooting
Facts Not Being Cached
Stale Facts
Facts Not Available in Playbook
Ensure:
- Job Template has
use_fact_cache: true - Facts were gathered in a previous job with caching enabled
- Facts are not older than the cache timeout
- Hosts are in the same inventory
Best Practices
Set Appropriate Timeouts
Configure cache timeout based on infrastructure change frequency
Use gather_facts: no
Skip gathering when using cached facts for better performance
Monitor Cache Size
Large inventories with many facts can consume significant database space
Regular Refreshes
Periodically run full fact gathering jobs to ensure cache freshness