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.
In check mode, Ansible runs without making any changes on remote systems. Modules that support check mode report the changes they would have made. Modules that do not support check mode report nothing and do nothing. In diff mode, Ansible provides before-and-after comparisons.
The easiest way to use the dry_run feature is to include the –check or -C options in the ansible-playbook command. Let us take an example of a playbook that installs an Apache HTTP and UFW firewall and creates a rule to allow HTTP traffic on port 80. The above command will run the playbook in check mode.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With