Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
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
8 changes: 6 additions & 2 deletions roles/database_apply/database_apply-drupal7/tasks/ctools.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
- name: Check if Ctools module is enabled.
shell: "cd {{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }} &&{{ drush_bin }}pm-info ctools | grep ': enabled' | wc -l"
ansible.builtin.shell:
cmd: "{{ drush_bin }} pm-info ctools | grep ': enabled' | wc -l"
chdir: "{{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }}"
register: ctools_enabled

- name: Revert Drupal configuration from Ctools.
shell: "cd {{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }} &&{{ drush_bin }}-y ctools-export-revert --all"
ansible.builtin.command:
cmd: "{{ drush_bin }} -y ctools-export-revert --all"
chdir: "{{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }}"
when: ctools_enabled.stdout == "1"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Sync database.
include_tasks: "sync.yml"
ansible.builtin.include_tasks: "sync.yml"
with_items: "{{ mysql_sync.databases }}"
loop_control:
loop_var: database
Expand Down
32 changes: 17 additions & 15 deletions roles/sync/database_sync/database_sync-mysql/tasks/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
- database.target.asg | length > 0

- name: Register remote dump name (from database).
set_fact:
ansible.builtin.set_fact:
mysql_sync_source_dump_path: "/tmp/{{ database.source.database }}.sql.bz2"

- name: Get source last known good build number.
command:
ansible.builtin.command:
argv:
- "/bin/sh"
- "{{ _ce_deploy_base_dir }}/scripts/track-get.sh"
Expand All @@ -51,17 +51,17 @@
when: database.source.type == 'rolling'

- name: Register source database name.
set_fact:
ansible.builtin.set_fact:
mysql_sync_source_database: "{{ database.source.database }}_{{ mysql_sync_source_build_number.stdout }}"
when: database.source.type == 'rolling'

- name: Register source database name.
set_fact:
ansible.builtin.set_fact:
mysql_sync_source_database: "{{ database.source.database }}"
when: not database.source.type == 'rolling'

- name: Take a dump from source database.
shell: "mysqldump --defaults-extra-file={{ database.source.credentials_file }} {{ mysql_sync.mysqldump_params }} {{ mysql_sync_source_database }} | bzip2 > {{ mysql_sync_source_dump_path }}"
ansible.builtin.shell: "mysqldump --defaults-extra-file={{ database.source.credentials_file }} {{ mysql_sync.mysqldump_params }} {{ mysql_sync_source_database }} | bzip2 > {{ mysql_sync_source_dump_path }}"
delegate_to: "{{ database.source.host }}"
when:
- database.source.fresh_db
Expand All @@ -88,11 +88,11 @@
when: not database.source.fresh_db

- name: Register tmp target dump name.
set_fact:
ansible.builtin.set_fact:
mysql_sync_target_dump_path: "/tmp/{{ database.target.database }}.sql.bz2"

- name: Get target last known good build number.
command:
ansible.builtin.command:
argv:
- "/bin/sh"
- "{{ _ce_deploy_base_dir }}/scripts/track-get.sh"
Expand All @@ -103,38 +103,40 @@
when: database.target.type == 'rolling'

- name: Register target database name.
set_fact:
ansible.builtin.set_fact:
mysql_sync_target_database: "{{ database.target.database }}_{{ mysql_sync_target_build_number.stdout }}"
when: database.target.type == 'rolling'

- name: Register target database name.
set_fact:
ansible.builtin.set_fact:
mysql_sync_target_database: "{{ database.target.database }}"
when: not database.target.type == 'rolling'

- name: Fetch dump file.
fetch:
ansible.builtin.fetch:
src: "{{ mysql_sync_source_dump_path }}"
dest: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
flat: true
delegate_to: "{{ database.source.host }}"

- name: Copy dump file to destination.
copy:
ansible.builtin.copy:
src: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
dest: "{{ mysql_sync_target_dump_path }}"

- name: Drop target database.
shell: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'drop database if exists {{ mysql_sync_target_database }};'"
ansible.builtin.command:
cmd: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'drop database if exists {{ mysql_sync_target_database }};'"

- name: Recreate target database.
shell: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'create database {{ mysql_sync_target_database }};'"
ansible.builtin.command:
cmd: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'create database {{ mysql_sync_target_database }};'"

- name: Repopulate database from dump.
shell: "bzcat {{ mysql_sync_target_dump_path }} | mysql --defaults-extra-file={{ database.target.credentials_file }} {{ mysql_sync_target_database }}"
ansible.builtin.shell: "bzcat {{ mysql_sync_target_dump_path }} | mysql --defaults-extra-file={{ database.target.credentials_file }} {{ mysql_sync_target_database }}"

- name: Remove tmp dump file.
file:
ansible.builtin.file:
path: "{{ mysql_sync_target_dump_path }}"
state: absent

Expand Down
2 changes: 1 addition & 1 deletion roles/sync/database_sync/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Sync databases.
include_role:
ansible.builtin.include_role:
name: "sync/database_sync/database_sync-{{ engine }}"
with_items: "{{ database_sync.engines }}"
loop_control:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
# Drupal 8 ships drush with the website code so we need the previous build in the path.
- name: Stash the drush_bin variable.
ansible.builtin.set_fact:
_drush_bin_deploy: "{{ drush_bin }}"

- name: Update location of drush for the sync cache clear command.
ansible.builtin.set_fact:
drush_bin: "{{ live_symlink_dest }}/vendor/bin/drush"

- name: Clear Drupal cache.
ansible.builtin.command:
cmd: "{{ drush_bin }} -l {{ site.folder }} -y cr"
Expand All @@ -9,3 +18,7 @@
loop_control:
loop_var: site
run_once: true

- name: Restore the drush_bin variable.
ansible.builtin.set_fact:
drush_bin: "{{ _drush_bin_deploy }}"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Apply Drupal database updates.
ansible.builtin.shell:
ansible.builtin.command:
cmd: "{{ drush_bin }} -l {{ site.folder }} -y updb"
chdir: "{{ live_symlink_dest }}/{{ webroot }}/sites/{{ site.folder }}"
with_items: "{{ drupal.sites }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
# Drupal 8 ships drush with the website code so we need the previous build in the path.
- name: Stash the drush_bin variable.
ansible.builtin.set_fact:
_drush_bin_deploy: "{{ drush_bin }}"

- name: Update location of drush for the update/config import commands.
ansible.builtin.set_fact:
drush_bin: "{{ live_symlink_dest }}/vendor/bin/drush"

- name: Apply Drupal database updates.
ansible.builtin.command:
cmd: "{{ drush_bin }} -l {{ site.folder }} -y updb"
Expand Down Expand Up @@ -26,3 +35,7 @@
- name: Clear the cache.
ansible.builtin.include_role:
name: "sync/drupal_sync_tasks/cache_clear/cache_clear-{{ project_type }}"

- name: Restore the drush_bin variable.
ansible.builtin.set_fact:
drush_bin: "{{ _drush_bin_deploy }}"
2 changes: 1 addition & 1 deletion roles/sync/files_sync/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Sync files.
include_tasks: "sync.yml"
ansible.builtin.include_tasks: "sync.yml"
with_items: "{{ files_sync.directories }}"
loop_control:
loop_var: files
Expand Down