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:
- Run prod only from CI/AWX with an approval step, and make local runs read-only (no prod vault password on laptops).
- Require a
--limitfor prod with an assertion on the first play. - 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.
More on Project Structure and Design
What does a production Ansible repository look like?BeginnerMonorepo or separate repos for roles? How do you decide?IntermediateHow do you structure inventories for dev, stage and prod?BeginnerWhat does "thin playbooks, fat roles" mean?IntermediateWhat makes a well-designed role?IntermediateWhat goes into a project-level `ansible.cfg` for production?Beginner