Interview Prep/Ansible/Project Structure and Design

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: true keeps a timestamped copy.
  • Use reload instead of restart where the service supports it.
  • Roll out in batches with serial and 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
All Ansible questions Roadmap: Ansible

More on Project Structure and Design