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 option 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

 



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 e4b9d 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   |