A Line-by-Line Ansible Review Found Three Credentials in the Wrong Place
An earlier infrastructure-as-code review had checked Terraform completely and Ansible only by spot-check. A full pass over all 73 roles found three templates that embedded live credentials with loose permissions, each next to a sibling task that already did it correctly.

Key Architectural Takeaways
- Audit the gap your last review left open: ours was Terraform-complete and Ansible-spot-checked.
- Look for inconsistency inside a role; the correct pattern was already present next to each mistake.
- Code-only fixes to production roles wait for review and a check-mode diff before any live run.
The challenge
An earlier IaC review had been thorough on Terraform and only a spot-check on Ansible, and it said so, leaving the gap open. This pass closed it: a full, line-by-line read of all 73 Ansible roles.
What did not recur
First the good news. A bug class the repo had hit five times before, wrong changed_when and until conditions that make a playbook report success it did not earn, was checked directly across the fleet and is not recurring. Nothing to fix there.
What was found
Seventeen templates fleet-wide embed a live credential. Three of them were deployed wrongly: world-readable (0644), or with a secret baked in as a literal inside an executable script. In each case the same role already did it correctly elsewhere, with a mode-0600 environment file or a secret reference:
- The monitoring configuration embedded a DNS reader token at
0644. It is now0640, matching a sibling template in the same role. - A forced-command script on the SIEM manager had the API password templated straight into a
0755file. It now reads the credential at runtime from a new0600environment file, mirroring the same role's other tool. - An assistant gateway config held its auth token as a literal at
0644, while the bot tokens in the same file used secret references. It is now0600.
That pattern, the correct approach one task away from the wrong one, is typical of drift: nobody decided to be insecure, one template was written before the habit existed.
Verification
Syntax checks passed on all three affected playbooks. Both modified templates rendered correctly with fake credential values, the rewritten script's output parsed as valid Python, and a functional test imported the script's own password-loading function against the rendered env file and confirmed it read back the fake value.
What was deliberately not done
Nothing was deployed. The three roles run on real, in-use production hosts, and changing a permission mode or a credential's location there is a security-relevant action. The live run and the merge waited for review, with check-mode diffs on each host as the test plan to confirm "the intended mode change and nothing else".
Takeaway
Search for inconsistency, not just for mistakes. The cheapest fix for a leaked-credential pattern is the pattern you already trust in the next file over.
Some of what's described here is a design that hasn't been fully tested yet; those parts say so in the text.