ansible 中的 check 模式和 diff 模式到底神马意思?

2017-10-13 17:26:47 +08:00
 hagezhou

最新在使用 ansible,也看了下 ansible 的 python api,发现里面有个 check 和 diff 模式

从官方文档的解释是这样 “当以 --check 参数来运行 ansible-playbook 时,将不会对远程的系统作出任何更改.” 从-h 中看到 “ -C, --check don't make any changes; instead, try to predict some of the changes that may occur -D, --diff when changing (small) files and templates, show the differences in those files; works great with --check ”

但其实还是不明白,尤其是使用 command 或者 shell 模块的时候,更是一点区别也感觉不出来,求大神解释,谢谢

5882 次点击
所在节点    Ansible
6 条回复
cxbig
2017-10-13 17:42:55 +08:00
command 或 shell 在没有添加 when 条件做制约的时候总是会运行的,所以 dry run 对这两个模块没有什么用处。
cxbig
2017-10-13 17:46:34 +08:00
文档说的很清楚
check 是告诉你每个 task 会不会执行
diff 主要针对 template/lineinfile/blockinfile/replace 这类模块的
hagezhou
2017-10-13 17:57:05 +08:00
@cxbig 哦哦,那 diff 的话理解了,check 每个 task 会不会执行的话在 shell 或者 command 模块中会有体现吗?我加上 check 参数和不加也没看到什么区别,也没有打屏输出会不会执行什么的
cxbig
2017-10-13 18:07:19 +08:00
@hagezhou
我在#1 里说的
如果你不加 when 这类判断的话,shell 和 command 每次都会执行
如果 when 条件是 false,那就会是 skip

没有看到区别??怎么会?这是我的一个 check 结果:
......
TASK [scripts : Check deploy folder]
changed: [srv-0]
......
PLAY RECAP
srv-0 : ok=4 changed=2 unreachable=0 failed=0

很清晰的告诉我这个 task 会执行
hagezhou
2017-10-16 10:35:45 +08:00
@cxbig 原来是有 when 判断的时候才会有效果,理解了,谢谢
sgaoc
2019-09-19 02:33:31 +08:00
- name: Get the school server
shell: DOMAIN={{ school_config.url }} && echo ${DOMAIN#*.}
register: domain_name

我的 shell 模块如上,没有 when 判断条件,但在执行 --check --diff 的时候也被跳过了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/397413

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX