如何在 ansible 检查模式下 运行 一个 shell 命令?

How to run a shell command in ansible's check mode?

在检查模式下,我想显示服务器中的当前提交。我正在使用 shell 命令 (git rev-parse HEAD) 注册变量,然后 print/debug 它但是 ansible 在检查模式下跳过 shell 命令。

有没有办法在检查模式下将 shell 命令标记为对 运行 安全?

或者任何 ansible 模块来做我想做的事?我检查了 git 的模块,但它看起来只是结帐。

如有任何意见,我们将不胜感激。

找到答案了。您必须将 always_run: True 添加到任务中。

从Ansible 2.2开始,the right way to do it就是使用check_mode: no:

tasks:
  - name: this task will make changes to the system even in check mode
    command: /something/to/run --even-in-check-mode
    check_mode: no