Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: anonymization using DbToolsBundle #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.