2016-04-04 22:03:17 +00:00
.. _check_mode_dry:
2013-09-29 20:19:59 +00:00
Check Mode ("Dry Run")
======================
2013-02-23 19:34:29 +00:00
.. versionadded :: 1.1
2013-12-26 19:32:01 +00:00
.. contents :: Topics
2014-01-22 05:05:21 +00:00
When ansible-playbook is executed with `` --check `` it will not make any changes on remote systems. Instead, any module
2013-10-05 18:57:45 +00:00
instrumented to support 'check mode' (which contains most of the primary core modules, but it is not required that all modules do
this) will report what changes they would have made rather than making them. Other modules that do not support check mode will also take no action, but just will not report what changes they might have made.
2013-02-23 19:34:29 +00:00
Check mode is just a simulation, and if you have steps that use conditionals that depend on the results of prior commands,
it may be less useful for you. However it is great for one-node-at-time basic configuration management use cases.
Example::
ansible-playbook foo.yml --check
2013-10-04 22:34:39 +00:00
.. _forcing_to_run_in_check_mode:
2013-08-20 21:09:44 +00:00
Running a task in check mode
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
.. versionadded :: 1.3
Sometimes you may want to have a task to be executed even in check
2013-09-05 19:20:02 +00:00
mode. To achieve this, use the `always_run` clause on the task. Its
value is a Jinja2 expression, just like the `when` clause. In simple
2013-08-20 21:09:44 +00:00
cases a boolean YAML value would be sufficient as a value.
Example::
tasks:
- name: this task is run even in check mode
command: /something/to/run --even-in-check-mode
always_run: yes
As a reminder, a task with a `when` clause evaluated to false, will
still be skipped even if it has a `always_run` clause evaluated to
2016-01-20 18:47:09 +00:00
true.
Also if you want to skip, or ignore errors on some tasks in check mode
you can use a boolean magic variable `ansible_check_mode` (added in version 2.1)
which will be set to `True` during check mode.
Example::
tasks:
- name: this task will be skipped in check mode
git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello
when: not ansible_check_mode
- name: this task will ignore errors in check mode
git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello
ignore_errors: "{{ ansible_check_mode }}"
2013-08-20 21:09:44 +00:00
2013-10-04 22:34:39 +00:00
.. _diff_mode:
2013-08-20 21:09:44 +00:00
2014-01-22 05:05:21 +00:00
Showing Differences with `` --diff ``
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2013-02-23 19:34:29 +00:00
.. versionadded :: 1.1
2014-01-22 05:05:21 +00:00
The `` --diff `` option to ansible-playbook works great with `` --check `` (detailed above) but can also be used by itself. When this flag is supplied, if any templated files on the remote system are changed, and the ansible-playbook CLI will report back
the textual changes made to the file (or, if used with `` --check `` , the changes that would have been made). Since the diff
2013-02-23 19:34:29 +00:00
feature produces a large amount of output, it is best used when checking a single host at a time, like so::
ansible-playbook foo.yml --check --diff --limit foo.example.com