How-Tos

How-To: Preview What Ansible Would Change Before It Changes It

Leave a comment

Every server change I make goes through Ansible, and before a playbook touches anything I want to see what it would do. Check mode plus diff mode is how.

1. Dry run with diffs

ansible-playbook site.yml --check --diff

--check runs without making changes; --diff shows the before/after for templates and files. Tasks report “changed” if they would change.

2. Narrow it down

ansible-playbook site.yml --check --diff --limit webservers --tags nginx

Start with one group or one host, and one role’s tags, so the output is something you’ll actually read.

3. Know what check mode can’t predict

command and shell tasks are skipped in check mode unless you tell them otherwise, and tasks that depend on an earlier task’s real result may fail. For a safe read-only task you want to run anyway, set it explicitly:

- name: Read current version
  ansible.builtin.command: nginx -v
  check_mode: false
  changed_when: false

4. Then run it for real, small first

ansible-playbook site.yml --diff --limit one-test-host

If the real run matches the preview, roll it out to the rest. If not, figure out why before you go wider.

God Bless, and May the Source Be with You!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.