Skip to content

Instantly share code, notes, and snippets.

@CrackerJackMack
Last active September 6, 2022 22:34
Show Gist options
  • Save CrackerJackMack/a4e1bf70e1bf73d460b5c97eb645f473 to your computer and use it in GitHub Desktop.
Save CrackerJackMack/a4e1bf70e1bf73d460b5c97eb645f473 to your computer and use it in GitHub Desktop.
ansible fact caching redis password different port

Everything I've read is that redis fact caching in ansible doesn't support db/password/ports, but that is untrue. It's undocumented and it will most likely change in the future but here is how it works. it takes the fact_caching_connection and split's it on the colon and passes it as *args to redis.StrictRedis. Db is typically 0 if you weren't sure. If you aren't sure if the ansible version you are using supports this, just check the plugins/redis.py for how it passes the connection string to StrictRedis. Works with 2.2.0.0 at least.

# hostname:port:db:password
localhost:6379:0:secret
public_ip:293451:0:supersercretnobodycanguessthis
[defaults]
gathering: smart
fact_caching = redis
fact_caching_timeout = 600
fact_caching_connection = hostname:port:db:password
fact_caching_prefix = 'ansible:'
---
# force insert all keys into redis, just an example or run via cron. whatever
- name: prime redis cache
hosts: all
gather_facts: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment