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

Sof*_*fia 12 git shell ansible

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

无论如何将shell命令标记为在检查模式下运行是否安全?

或任何ansible模块做我想要的?我检查了git的模块,但它看起来只是检查.

任何输入将不胜感激.

Sof*_*fia 11

找到了答案.您必须添加always_run: True到任务.

  • 既然有更好的方法,我认为接受的答案应该更改为@jfrenetic 的答案。 (2认同)

jFr*_*tic 10

从Ansible 2.2开始,正确的方法是使用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
Run Code Online (Sandbox Code Playgroud)

  • 哇,“check_mode: no”意味着是,在检查模式下运行它?‘不’是什么意思? (7认同)