Interview Prep/Ansible/Project Structure and Design

How do you prevent someone from running a playbook against production by accident?

IntermediateProductionProject Structure and Design
Answer

Layer the guards, since none is perfect:

  1. Run prod only from CI/AWX with an approval step, and make local runs read-only (no prod vault password on laptops).
  2. Require a --limit for prod with an assertion on the first play.
  3. Add an explicit confirmation for destructive plays.
- hosts: all
  gather_facts: false
  tasks:
    - ansible.builtin.assert:
        that: ansible_limit is defined
        fail_msg: "Prod runs need --limit"
      run_once: true
      when: env == 'prod'

Separate credentials per environment is the real control: if you cannot log in, you cannot break it.

All Ansible questions Roadmap: Ansible

More on Project Structure and Design