Interview Prep/Ansible/Architecture Decisions and Tool Comparisons

Ansible or Flyway/Liquibase for database schema changes?

BeginnerProductionArchitecture Decisions and Tool Comparisons
Answer

Use a migration tool (Flyway, Liquibase, Alembic, Django or Rails migrations) for the schema. They track which migrations ran in a table, apply them in order and stay with the application code.

Ansible's role is around it:

  • Install and configure the database server, users, grants and backups (community.postgresql, community.mysql).
  • Run the migration tool once, at the right point in a rolling deploy, with run_once: true.
- name: Apply schema migrations
  ansible.builtin.command: /opt/app/bin/migrate up
  run_once: true
  register: mig
  changed_when: "'No migrations' not in mig.stdout"

Writing raw SQL schema changes as Ansible tasks loses ordering and history and makes rollbacks guesswork.

All Ansible questions Roadmap: Ansible

More on Architecture Decisions and Tool Comparisons