简体   繁体   中英

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

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.

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

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

Any input would be appreciated.

Starting from Ansible 2.2, the right way to do it is to use 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM