Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

shell

ansible

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.

like image 838
scc Avatar asked May 09 '15 12:05

scc


People also ask

What is check mode in Ansible?

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.

How do I run playbook in Dry Run mode?

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.


2 Answers

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
like image 96
jFrenetic Avatar answered Oct 05 '22 08:10

jFrenetic


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

like image 44
scc Avatar answered Oct 05 '22 08:10

scc