All articles

Ansible changes you can inspect, repeat and explain

A small lab example for turning a manual configuration change into a reviewable playbook, with realistic limits on check mode.

Describe the result before the commands

A manual instruction often sounds like “log in, edit this file, then check it.” Automation needs a clearer contract: which file should exist, what it should contain, who should own it, and how to verify the result.

Ansible playbooks express tasks against an inventory of hosts. For file management, a module such as ansible.builtin.copy makes the desired content and permissions explicit. That is easier to review than a collection of shell substitutions whose behavior depends on the previous file. The playbook guide explains this task and inventory model.

Begin with a narrow change. A successful demonstration should be understandable to another engineer without requiring the rest of your automation repository.

A deliberately small lab

This example writes a non-secret note on disposable Linux hosts in an inventory group named lab. It assumes a configured SSH connection, Python on the target and permission to become root. Adapt the inventory to your lab; the example is not a production rollout.

---
- name: Maintain a lab operations note
  hosts: lab
  become: true
  tasks:
    - name: Set the operations note
      ansible.builtin.copy:
        dest: /etc/operations-note
        content: "Managed by Ansible.\n"
        owner: root
        group: root
        mode: '0644'

Save it as operations-note.yml. Review the exact destination and content before executing it. There is intentionally no service restart: changing a note does not require one.

Inspect the change and its limits

ansible-playbook -i inventory.ini operations-note.yml --syntax-check
ansible-playbook -i inventory.ini operations-note.yml --check --diff --limit lab-node-01

Replace lab-node-01 with the inventory name of one lab host. Check mode reports predicted changes for supported modules; it is a simulation, not proof that a full run will succeed. Tasks depending on earlier registered results may behave differently, and tasks explicitly marked check_mode: false can still run normally. Diff output can expose file contents, so do not use it blindly for secrets. See Ansible’s check and diff mode documentation.

Review an unexpected change before increasing the host scope. A useful question is whether the output matches the intent you wrote down, not simply whether the command completed.

Run twice, then verify the result

After reviewing the preview, apply the playbook to the same disposable host without --check. Run it again. With the intended content already present, this copy task should report no further change. Then inspect the file itself and its permissions.

For real services, extend that verification to behavior: does the service answer, and does it use the new configuration? A handler can connect a configuration change to a necessary reload or restart. Keep that operation separate and named so the reviewer can understand its purpose. Handlers run when notified by changed tasks.

Repeatability is useful evidence, but it is not the entire acceptance test. A repeatable incorrect configuration is still incorrect. Keep the intended outcome, the observed change and the application check together in the review.

References

Official documentation. Match commands and behavior to your installed versions.

Continue with a practical course

Explore the related video lessons and build on these foundations.

Explore the course