Sep*_*ari 10 caching ansible ansible-facts
我正在努力使Ansible与--limit一起工作并且这样做我需要关于其他主机的事实,我正在使用fact_caching进行缓存.我应该运行什么命令,以便它只是收集所有主机上的所有事实并缓存它们,而不运行任何任务?如果它缓存了它收集的事实,那么设置模块之类的东西将是完美的,但它似乎没有.
alf*_*era 28
以下是我如何解决问题:
1.-在你的剧本上启用事实收集(site.yml):
gather_facts: yes
Run Code Online (Sandbox Code Playgroud)
2.- 在ansible.cfg上启用事实缓存:
2.1.-选项1 - 如果您有时间安装redis,请使用此选项:
[defaults]
gathering = smart
fact_caching = redis
# two hours timeout
fact_caching_timeout = 7200
Run Code Online (Sandbox Code Playgroud)
2.2.-选项2 - 使用它来测试现在很简单但比redis慢:
[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/facts_cache
# two hours timeout
fact_caching_timeout = 7200
Run Code Online (Sandbox Code Playgroud)
3.-更新或创建事实缓存.为此,只需一个任务即可创建一个新角色(缓存更新):执行ping.我们使用ping是因为它是最简单和最快速的任务,因此它可以帮助我们快速更新缓存:
- name: Pinging server to update facts cache
ping:
Run Code Online (Sandbox Code Playgroud)
问候,