How do you change config files safely so a bad render does not cause an outage?
BeginnerProductionProject Structure and Design
Answer
validate:runs a syntax check on the rendered temp file before it replaces the real one.backup: truekeeps a timestamped copy.- Use
reloadinstead ofrestartwhere the service supports it. - Roll out in batches with
serialand a health check after the change.
- ansible.builtin.template:
src: sshd_config.j2
dest: /etc/ssh/sshd_config
validate: /usr/sbin/sshd -t -f %s
backup: true
notify: Reload sshd
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?BeginnerHow do you prevent someone from running a playbook against production by accident?IntermediateWhat does "thin playbooks, fat roles" mean?IntermediateWhat makes a well-designed role?Intermediate