Skip to content

Commit

Permalink
feat: anonymization using DbToolsBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmirloup committed Jan 29, 2025
1 parent 25242ec commit 7de9d1b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,15 @@ Sync local PostgreSQL or MySQL database with remote.
Requirements
------------

The local system need to have either `pg_dump` and `pg_reload` command or `mysql` and `mysqldump`.
The following CLI commands need to be installed on your system / Docker image :

- PostgreSQL: `pg_dump` and `pg_restore`
- MySQL: `mysqldump` and `mysql`

Role Variables
--------------

The `defaults` vars declared in this module:

```
db_pull_remote_backup_path: /tmp/db-pull
db_pull_local_backup_path: /tmp/db-pull
db_pull_keep_backup: 5
db_pull_remote_database_user: postgres
db_pull_remote_database_host: localhost
db_pull_remote_database_name: postgres
db_pull_remote_database_password: root
db_pull_remote_database_port: 5432
db_pull_local_database_user: postgres
db_pull_local_database_host: localhost
db_pull_local_database_name: postgres
db_pull_local_database_password: root
db_pull_local_database_port: 5432
db_pull_database_type: postgres
db_pull_skip_restore: false
db_pull_exclude_table: []
db_pull_exclude_table_data: []
```
`defaults` vars declared in this module can be found here: [defaults/main.yml](defaults/main.yml)

Example Playbook
----------------
Expand All @@ -55,4 +33,4 @@ MIT
Author Information
------------------

* ansible-db-pull, written by Erwan Richard
* ansible-db-pull, written by Erwan Richard
16 changes: 16 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ db_pull_skip_restore: false

db_pull_exclude_table: []
db_pull_exclude_table_data: []

db_pull_anonymization: false

db_pull_anonymization_remote_database_user: postgres
db_pull_anonymization_remote_database_host: localhost
db_pull_anonymization_remote_database_name: postgres
db_pull_anonymization_remote_database_password: root
db_pull_anonymization_remote_database_port: 5432

db_pull_anonymization_remote_database_url: "postgresql://{{ db_pull_anonymization_remote_database_user }}:{{ db_pull_anonymization_remote_database_password }}@{{ db_pull_anonymization_remote_database_host }}:{{ db_pull_anonymization_remote_database_port }}/{{ db_pull_anonymization_remote_database_name }}?serverVersion=17"

db_pull_anonymization_command: >-
chdir={{ ansistrano_deploy_to }}/current
DATABASE_URL="{{ db_pull_anonymization_remote_database_url }}"
APP_ENV={{ symfony_env }}
php bin/console db-tools:anonymize --local-database --no-restore -n {{ db_pull_remote_backup_path }}/{{ db_pull_remote_database_name }}-{{ ansible_date_time.iso8601 }}.dump
4 changes: 2 additions & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ galaxy_info:
author: Erwan Richard
description: One way sync between remote and local databases
company: Le Phare
issue_tracker_url: https://github.com/erichard/ansible-database-sync
issue_tracker_url: https://github.com/le-phare/ansible-db-pull/issues

license: MIT

min_ansible_version: 1.2
min_ansible_version: "1.2"

galaxy_tags:
- database
Expand Down
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- include_tasks: "{{ db_pull_database_type }}/dump.yml"
when: local_dump.matched == 0

- name: Anonymize using DbToolsBundle
shell: {{ db_pull_anonymization_command }}
when: db_pull_anonymization

- name: Ensure database dump folder exists
delegate_to: localhost
become: false
Expand Down
8 changes: 0 additions & 8 deletions tasks/mysql.yml

This file was deleted.

7 changes: 0 additions & 7 deletions tasks/postgres.yml

This file was deleted.

0 comments on commit 7de9d1b

Please sign in to comment.