Best Practices¶
1. Always Use Dry-Run¶
Preview changes before applying:
2. Organize by Purpose¶
project/
├── main.yml
├── tasks/
│ ├── common.yml
│ ├── dev.yml
│ └── prod.yml
└── vars/
├── dev.yml
└── prod.yml
3. Use Variables¶
Make configs reusable:
4. Tag Your Workflows¶
- name: Dev setup
shell: install-dev-tools
tags: [dev]
- name: Prod deploy
shell: deploy-prod
tags: [prod]
5. Document Conditions¶
# Ubuntu 20+ only (older versions incompatible)
- name: Install package
shell: apt install package
when: distribution == "ubuntu" and distribution_major >= "20"
6. Use System Facts¶
7. Test Incrementally¶
- Start simple
- Test with
--dry-run - Add complexity gradually
- Use
--log-level debug