How do you ensure an unattended playbook run cannot execute arbitrary commands via extra vars?
AdvancedScenarioSecurity: Vault, Become and Compliance
Answer
Situation read → User input reaching command/shell is code execution.
What I'd do →
- Validate inputs with
assertandargument_specs. - Quote with
| quotein shell strings. - Avoid
shellwhen a module exists. - In AWX, use surveys with typed fields and disallow ad hoc
-efor non-admins ("prompt on launch" off).
- ansible.builtin.shell: "rm -rf {{ cleanup_dir | quote }}"
Why → Unvalidated variables into shell lines are injection vectors.
Interview tip → Mention !unsafe for data that must not template.
More on Security: Vault, Become and Compliance
Database passwords are sitting in plain text in `group_vars`. How do you fix it?BeginnerYou need separate vault passwords for staging and prod.IntermediateHow do you change the vault password for all encrypted files?IntermediateA CI pipeline needs the vault password without storing it in the repo.IntermediateYou want to see the value inside an encrypted file without writing a decrypted copy to disk.BeginnerOnly one value in a vars file is secret and you want it in the same file as plain values.Beginner