Interview Prep/Ansible/Security: Vault, Become and Compliance

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 →

  1. Validate inputs with assert and argument_specs.
  2. Quote with | quote in shell strings.
  3. Avoid shell when a module exists.
  4. In AWX, use surveys with typed fields and disallow ad hoc -e for 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.

All Ansible questions Roadmap: Ansible

More on Security: Vault, Become and Compliance