/docsite/rst/playbooks_checkmode.rst

https://github.com/ajanthanm/ansible · ReStructuredText · 55 lines · 35 code · 20 blank · 0 comment · 0 complexity · 89c224b5bdd3a9b1c0fcf3ad2055fcff MD5 · raw file

  1. Check Mode ("Dry Run")
  2. ======================
  3. .. versionadded:: 1.1
  4. .. contents:: Topics
  5. When ansible-playbook is executed with ``--check`` it will not make any changes on remote systems. Instead, any module
  6. instrumented to support 'check mode' (which contains most of the primary core modules, but it is not required that all modules do
  7. 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.
  8. Check mode is just a simulation, and if you have steps that use conditionals that depend on the results of prior commands,
  9. it may be less useful for you. However it is great for one-node-at-time basic configuration management use cases.
  10. Example::
  11. ansible-playbook foo.yml --check
  12. .. _forcing_to_run_in_check_mode:
  13. Running a task in check mode
  14. ````````````````````````````
  15. .. versionadded:: 1.3
  16. Sometimes you may want to have a task to be executed even in check
  17. mode. To achieve this, use the `always_run` clause on the task. Its
  18. value is a Jinja2 expression, just like the `when` clause. In simple
  19. cases a boolean YAML value would be sufficient as a value.
  20. Example::
  21. tasks:
  22. - name: this task is run even in check mode
  23. command: /something/to/run --even-in-check-mode
  24. always_run: yes
  25. As a reminder, a task with a `when` clause evaluated to false, will
  26. still be skipped even if it has a `always_run` clause evaluated to
  27. true.
  28. .. _diff_mode:
  29. Showing Differences with ``--diff``
  30. ```````````````````````````````````
  31. .. versionadded:: 1.1
  32. 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
  33. the textual changes made to the file (or, if used with ``--check``, the changes that would have been made). Since the diff
  34. feature produces a large amount of output, it is best used when checking a single host at a time, like so::
  35. ansible-playbook foo.yml --check --diff --limit foo.example.com