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

时间:2020-12-04 19:26:05

In check mode, I want to display the current commit in the server. I'm using the shell command (git rev-parse HEAD) to register the variable and then print/debug it but ansible skips shell commands in check mode.

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

Is there anyway to mark a shell command as safe to run in check mode?

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

Or any ansible module to do what I want? I checked into git's module but it only looks like it does checkouts.

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

Any input would be appreciated.

任何输入将不胜感激。

2 个解决方案

#1


Found the answer. You have to add always_run: True to the task.

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

#2


Starting from Ansible 2.2, the right way to do it is to use check_mode: no:

从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

#1


Found the answer. You have to add always_run: True to the task.

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

#2


Starting from Ansible 2.2, the right way to do it is to use check_mode: no:

从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