FreeKB - Ansible --check (dry run) command line flag
Ansible - --check (dry run) command line flag

There are two ways to determine if plays in a playbook will be successful, like a dry run, meaning that no changes will be made on the manage nodes (e.g. target systems)

The --check flag will check every play in a playbook. The check_mode parameter will only check certain plays in a playbook.


Let's say you've a playbook named foo.yml that is using the lineinfile parameter will append "Hello World" to /tmp/foo.txt, like this.

- name: "append 'World' to /tmp/foo.txt"
  lineinfile:
    path: "/tmp/foo.txt"
    line: "World"

 

Here is how to use the --check flag with the ansible-playbook command.

ansible-playbook foo.yml --check

 

Something like this should be returned.

TASK [append 'Hello World' to /tmp/foo.txt]
changed: [server1.example.com]

PLAY RECAP
server1.example.com : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

On the managed node, "Hello World" would not have been appended to /tmp/foo.txt. Now let's invoke the ansible-playbook command without the --check flag.

ansible-playbook foo.yml --check

 

This should produce the same exact output, which is something important to be aware of. The --check flag will not change the output produced by the ansible-playbook command. However, now, "Hello World" should have been appended to /tmp/foo.txt on the managed node. Just like the --check flag, the check_mode parameter will not change the output produced by the ansible-playbook command.

TASK [append 'Hello World' to /tmp/foo.txt]
changed: [server1.example.com]

PLAY RECAP
server1.example.com : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

Be aware that some modules, such as the uri module, do not support the --check flag. For modules that do not support check mode, the module can be skipped by including when not ansible_check_mode.

- name: determine if foo.txt exists
  uri:
    url: http://example.com/foo.txt
  when:
    - not ansible_check_mode

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 17ec4 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |