使用 ansible set_fact 模块来定义持久性事实?
using ansible set_fact module to define persistent facts?
我想定义一个剧本,它建立了关于我的主机的事实,可以在其他剧本中使用。 set_fact 模块声称能够做到这一点...... http://docs.ansible.com/set_fact_module.html - 然而它不起作用......我定义的事实在调用 set_fact 之后可用 [=剧本的 20=]——然后我希望能够使用 ansible all -m setup 并查看在为每个主机收集的事实中某处定义的事实...
我试着查看 set_fact 模块的代码——但我发现的只是文档字符串... https://github.com/ansible/ansible-modules-core/blob/19b328c4df2157b6c0191e9144236643ce2be890/utilities/logic/set_fact.py
您使用的是什么版本的 Ansible?从 1.8 版本开始,有一个内置的 fact caching capability,但默认情况下是禁用的。你需要在你的 ansible.cfg 文件中启用它,你还需要有一个 redis 服务器 运行 因为这是实际缓存事实的东西。
首先,set_fact 模块仅设置 运行 期间可用的事实。对于持久性事实,您需要:
--Static--
- define them in one of the following:
- vars/
- group_vars/
- host_vars/
--Dynamic--
Assign them to hosts using your language of choice via Ansible's Dynamic Inventory:
后者是我通常选择做的,因为它设置起来非常简单,而且所有主机上的事实总是可用的,即使你正在做类似的事情:
- getting all the facts for all the hosts while connected to a nagios host in order to generate its configuration files.
如果远程管理系统有一个 /etc/ansible/facts.d 目录,则此目录中以 .fact 结尾的任何文件都可以是 JSON、INI 或返回 JSON 的可执行文件,这些可以在 Ansible 中提供本地信息,从 1.3 开始。可以使用 fact_path 播放指令指定备用目录。
http://docs.ansible.com/ansible/playbooks_variables.html#local-facts-facts-d
我想定义一个剧本,它建立了关于我的主机的事实,可以在其他剧本中使用。 set_fact 模块声称能够做到这一点...... http://docs.ansible.com/set_fact_module.html - 然而它不起作用......我定义的事实在调用 set_fact 之后可用 [=剧本的 20=]——然后我希望能够使用 ansible all -m setup 并查看在为每个主机收集的事实中某处定义的事实...
我试着查看 set_fact 模块的代码——但我发现的只是文档字符串... https://github.com/ansible/ansible-modules-core/blob/19b328c4df2157b6c0191e9144236643ce2be890/utilities/logic/set_fact.py
您使用的是什么版本的 Ansible?从 1.8 版本开始,有一个内置的 fact caching capability,但默认情况下是禁用的。你需要在你的 ansible.cfg 文件中启用它,你还需要有一个 redis 服务器 运行 因为这是实际缓存事实的东西。
首先,set_fact 模块仅设置 运行 期间可用的事实。对于持久性事实,您需要:
--Static--
- define them in one of the following:
- vars/
- group_vars/
- host_vars/
--Dynamic--
Assign them to hosts using your language of choice via Ansible's Dynamic Inventory:
后者是我通常选择做的,因为它设置起来非常简单,而且所有主机上的事实总是可用的,即使你正在做类似的事情:
- getting all the facts for all the hosts while connected to a nagios host in order to generate its configuration files.
如果远程管理系统有一个 /etc/ansible/facts.d 目录,则此目录中以 .fact 结尾的任何文件都可以是 JSON、INI 或返回 JSON 的可执行文件,这些可以在 Ansible 中提供本地信息,从 1.3 开始。可以使用 fact_path 播放指令指定备用目录。
http://docs.ansible.com/ansible/playbooks_variables.html#local-facts-facts-d