← RHCE in Ansible: automation and operations
08 / 23 · 100 MIN

Templates, Vault, and RUN handover

Publish deterministic configuration and protect secrets during execution.

Concept and mechanism

A template turns variables into configuration and should produce stable content when intent has not changed. Inserting a new timestamp can notify restart on every run. Removing unnecessary volatile content preserves useful change signals; forcing changed_when false for everything can hide a real change requiring application.

The validate parameter checks a temporary file before publication using %s in the command. This mechanism does not interpret an arbitrary pipeline as Bash. Syntactic validation also does not replace functional checking after application or confirm that new sessions or consumers can use the service.

Guided application

Vault protects encrypted content at rest. After decryption, a task can expose the secret through debug, files, or artifacts. Protect each relevant output and destination and avoid collecting more sensitive content than necessary.

Storing the Vault password alongside encrypted content removes the separation protecting that access. Vault IDs identify sources and labels; they are not the key itself. In a fictional incident, a shared log contains a database credential.

Fixing the next job does not handle earlier exposure: restrict the artifact and coordinate rotation and investigation through the applicable process. For RUN, deliver executable procedures with operational access, versions, dependencies, and known limits without reliance on the author’s personal password.

Observe protection boundaries

The exercise encrypts a variable whose value is PUBLIC_DEMO_NOT_A_CREDENTIAL. Its password is also a public string created for the lab. Never replace these fixtures with production credentials when reproducing examples.

The encrypted file no longer contains the readable token. A copy task then uses the decrypted value, no_log:true and mode 0600. Captured logs omit the token, but the runtime file contains owner-readable bytes.

These are three distinct observations: encrypted source, protected task result and plaintext destination with restricted permissions. A later unprotected debug task prints the value again. Before adding debug during an incident, decide which evidence is needed without exposing contents.

In a real case, correcting future output does not remove copies already held in artifacts or logging systems.

Distinguish storage password from application credential

With the wrong password, the play fails before writing. The next step is to confirm decryption-material source and encrypted revision instead of broadening destination permissions to address an earlier failure. In the final run, core 2.16.14 default policy accepts the correct password even under another label.

The label helps select sources, but this observation prevents treating it as an authorization boundary. The first attempt set vault_id_match=False in INI; that installation read the setting as string "False" rather than the expected boolean.

The declaration was removed and the exercise repeated with the default. This occurrence calls for attention to version and effective configuration. Finally, rekey changes file protection: the previous password fails and the new one works, but the application token stays unchanged. An exposed credential requires separate handling.

Validate before replacement

Destination batch.conf starts with port=8080. The template produces a candidate containing port=5. The original validator reads the temporary file passed through %s, records only public path and port values, and rejects values outside 8080 or 9090.

Actual execution fails, retains the previous destination and creates no activation marker. Next, port=9090 is accepted, replaces the file and triggers the fictional handler. When reviewing a wrapper, confirm that it uses the supplied path: always validating the old destination could approve a new configuration without reading it.

If several checks are needed, implement an explicit wrapper with controlled arguments and consistent results. A pipeline written directly in validate does not acquire shell interpretation by default. This exercise marker represents only a notification, not service restart or consumer testing.

Use simulation and repetition with clear criteria

Before the invalid real execution, the lab runs the same port=5 candidate in check mode. The process finishes without error and retains batch.conf, but no validator record appears. Therefore that simulation does not prove candidate validation passed.

Promotion requires a rehearsal that executes the gate and functional criteria appropriate to the service. After accepting 9090, repeating the stable template produces changed=0 and does not run the handler again. This helps detect unnecessary restarts caused by volatile contents, but does not establish service availability.

Both complete runs passed 24 checks each across 13 invocations on core 2.16.14. All writes were local and tokens are public. RUN handover should explain authorized access sources, output protection, destination permissions, candidate validation and recovery from partial effects.

DEMONSTRATION DATA, NO REAL CREDENTIALS
Source Vault -> encrypted bytes
copy + no_log -> protected log, readable destination with mode 0600
later unprotected debug -> public value in log
rekey -> new file password; same application token
check mode port=5 -> validator not executed
real execution port=5 -> rejection, old 8080 retained
real execution port=9090 -> accepted
stable repeat -> changed=0, no new handler
IN PRACTICE

The file remains encrypted in Git, but the secret may already be readable in the execution artifact.

Common pitfalls

Vault as protection for every output; no_log as retroactive correction; syntax validation as complete acceptance.

Related topics: State and repeatability · Inventories, variables, and configuration · Access and execution environment

Take this idea with you

Trace the value from encrypted source to destination and logs; accept configuration only with evidence the rehearsal actually produced.

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.