gpt4 book ai didi

ansible - ansible 可以在剧本中间获取更新的事实吗?

转载 作者:行者123 更新时间:2023-12-04 05:11:55 24 4
gpt4 key购买 nike

我在运行完整的剧本时遇到了麻烦,因为后来的剧本所依赖的一些事实在早期的剧本中被修改了,但是 ansible 不会在运行中更新事实。

运行ansible somehost -m setup当整个剧本开始针对新的 VPS 时:

"ansible_selinux": {
"status": "disabled"
},

我的剧本包含一个安装 SELinux 并重新启动服务器的剧本(而 ansible wait_for 的),后面的任务使用条件 when: ansible_selinux.status != 'disabled' .然而,即使 SELinux 现在已安装并强制执行(这需要重新启动),系统的事实仍然显示 SELinux 已禁用,因此条件失败并跳过任务。

再次运行 playbook 当然可以,因为事实已更新并且现在返回:
"ansible_selinux": {
"config_mode": "enforcing",
"mode": "enforcing",
"policyvers": 28,
"status": "enabled",
"type": "targeted"
}

有没有办法让事实在剧本中刷新?也许黑客是到 set_fact重启后我自己在 ansible_selinux.status 上吗?

更新 :
嗯,这太容易了,感谢 BruceP,我在 SELinux 游戏结束时添加了这个任务来获取更新的事实
- name: SELinux - Force ansible to regather facts
setup: filter='ansible_selinux'

最佳答案

将此添加到您的剧本中以使用设置模块来更新事实。

例如,我添加了另一个带有 DHCP 的接口(interface),现在我想知道它有什么地址,然后执行以下操作:

- name: do facts module to get latest information
setup:

关于ansible - ansible 可以在剧本中间获取更新的事实吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35185635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com