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.
More on Architecture Decisions and Tool Comparisons
Ansible or Terraform: where do you draw the line?BeginnerHow does Ansible compare with Puppet, Chef and Salt?IntermediateWhy use Ansible instead of shell scripts?BeginnerWhere does Ansible fit once you run Kubernetes?Intermediatecloud-init or Ansible for first boot configuration?IntermediateWhen would you use AWS Systems Manager instead of, or together with, Ansible?Intermediate