← RHCE in Ansible: automation and operations
01 / 23 · 95 MIN

State and repeatability

Turn manual tasks into reproducible, verifiable state.

Concept and mechanism

A useful playbook describes conditions required for the outcome, including dependencies an administrator might have created manually. Running it on an old host can hide that preparation. Under EX294 objectives, playbooks are applied to fresh systems and configurations must persist after reboot.

Therefore, distinguish error-free execution, intended state, and reconstruction of that state at boot. A currently active mount does not prove persistent configuration exists. A directory readable by a group also needs search permission to allow traversal.

Its mode should represent access requirements without adding write merely to remove an error.

Guided application

In a fictional batch project, reproduce configuration on a disposable host and compare the initial execution with a repeat. A state module can avoid unnecessary changes; a command does not become idempotent simply by using register. Creates can prevent repetition when a reliable marker exists and is created only after validated success.

That marker does not replace validation of the migration it represents. In a registered result, rc, stdout, and changed mean different things. Document acceptable codes before building conditions.

Facts are observations too: ansible_date_time gathered at startup does not advance like a live clock. To measure a later phase, collect time evidence appropriate to that moment.

Measure state, reporting and consumption

The lab starts with a fresh directory and user-owned synthetic files. A copy task publishes port=8080 with mode 0640. The first execution changes the destination and the second reports changed=0.

Compare three things: published bytes, metadata and how a consumer uses the result. Unchanged repetition helps detect unnecessary work, but is acceptable only when retained state meets the request. Another destination already contains 8080 when the task starts requesting 9090 with force:false.

The exercise finishes unchanged and retains the old port. Absence of differences does not correct a contract that preserves outdated contents. For a real batch, acceptance should specify expected configuration and how it will be observed, alongside the automation exit code.

Repair drift invisible to a content hash

After the first repeat, the runner changes only stable.conf mode to 0666. Its content SHA-256 stays the same. Check mode predicts a change, but subsequent inspection still shows 0666.

Only actual execution restores 0640; another repeat returns to changed=0. This cycle demonstrates detection, prediction, repair and stability without confusing the four stages. If a pipeline compares only byte hashes, permission drift goes unnoticed.

The same care applies to owner, group and other environment-required attributes. Declared permissions also do not establish access for an identity absent from the exercise. This lab observes local mode without validating ACLs, SELinux or remote-service groups. That service’s acceptance needs its actual identity and context.

Do not hide effects behind change counts

An original script appends line effect to a file whenever called. The play runs it twice with changed_when:false. Both recaps show zero changes, but the file ends with two lines.

This observation separates the execution decision from reporting policy. If a requirement prohibits repeating an operation, define intended state or an execution condition supported by appropriate evidence. Do not substitute suppressed reporting.

Another experiment applies state:touch to an old marker and observes a new mtime. With access_time and modification_time explicitly set to preserve, the existing marker retains mtime and the task reports no change. Choose that policy only when marker meaning permits retained times; if it represents a recent execution, preserving an old timestamp would be misleading.

Repeat the exercise and hand over verifiable criteria

Predict which tasks should change files and which properties may remain wrong despite changed=0. Run the runner in a fresh directory and inspect retained observations. Both final runs passed 34 checks across 23 invocations each on core 2.19.0 and a local macOS filesystem.

Then change a copy of the inputs and repeat detection, repair and inspection. The exercise also creates mode-0664 destinations and changes their bytes without an explicit mode. Even with umask 0077, previous mode remains.

Declaring 0640 corrects it under both exercised umasks. Hand RUN the expected policy and corresponding observations, including evidence limits. Connect this lesson with data contracts, inventories, account permissions and template validation.

Remote services and reboot persistence still require their own rehearsals.

IN PRACTICE

The mount works before reboot; rehearsal ends only after confirming the mounted resource afterward.

Common pitfalls

Prepared host as universal proof; changed as success; marker created before validation.

Related topics: Inventories, variables, and configuration · Access and execution environment · Git, dev containers, and rehearsals

Take this idea with you

Check effects and required state; changed=0 is useful only with correct acceptance criteria.

Create account

References

Red Hat®, RHCE and Ansible are trademarks or registered trademarks of Red Hat, Inc. bigsavant.com is an independent preparation platform and is not affiliated with, associated with, sponsored, authorised or endorsed by Red Hat. Content and questions are original, are not official exam questions, and completing our tests does not award or guarantee any certification. Names are used only to identify the subject. All other trademarks belong to their respective owners.