V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Ansible
Ansible Documentation
hagezhou
V2EX  ›  Ansible

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

  •  
  •   hagezhou · 2017-10-13 17:26:47 +08:00 · 5826 次点击
    这是一个创建于 2358 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最新在使用 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 模块的时候,更是一点区别也感觉不出来,求大神解释,谢谢

    6 条回复    2019-09-19 02:33:31 +08:00
    cxbig
        1
    cxbig  
       2017-10-13 17:42:55 +08:00
    command 或 shell 在没有添加 when 条件做制约的时候总是会运行的,所以 dry run 对这两个模块没有什么用处。
    cxbig
        2
    cxbig  
       2017-10-13 17:46:34 +08:00
    文档说的很清楚
    check 是告诉你每个 task 会不会执行
    diff 主要针对 template/lineinfile/blockinfile/replace 这类模块的
    hagezhou
        3
    hagezhou  
    OP
       2017-10-13 17:57:05 +08:00
    @cxbig 哦哦,那 diff 的话理解了,check 每个 task 会不会执行的话在 shell 或者 command 模块中会有体现吗?我加上 check 参数和不加也没看到什么区别,也没有打屏输出会不会执行什么的
    cxbig
        4
    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
        5
    hagezhou  
    OP
       2017-10-16 10:35:45 +08:00
    @cxbig 原来是有 when 判断的时候才会有效果,理解了,谢谢
    sgaoc
        6
    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 的时候也被跳过了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:16 · PVG 05:16 · LAX 14:16 · JFK 17:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.