From 4b20477a03a4f6fbc1acb4926d7b032e8e59d102 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 25 Mar 2020 17:03:12 +0100
Subject: [PATCH] Implement tasks to copy database and assets from one stage to
 another

---
 tasks/copy_data/main.yml | 45 ++++++++++++++++++++++++++++++++++++++++
 tasks/main.yml           | 11 ++++++++++
 2 files changed, 56 insertions(+)
 create mode 100644 tasks/copy_data/main.yml

diff --git a/tasks/copy_data/main.yml b/tasks/copy_data/main.yml
new file mode 100644
index 0000000..7e98eea
--- /dev/null
+++ b/tasks/copy_data/main.yml
@@ -0,0 +1,45 @@
+---
+# file: roles/drupal/tasks/copy_data/main.yml
+
+- block:
+
+  - name: Set facts without jails
+    set_fact:
+      webRoot: /var/www{{ drupal.webRoot|default("") }}
+      cronUser: root
+      apacheUser: www-data
+      apacheLogDir: /var/log/apache2
+      drushSubkey: '{{ drupal.drush_subkey|default("") }}'
+    when: drupal.jail is not defined
+
+  - name: Set facts with jails
+    set_fact:
+      webRoot: '{{ jailroot }}/{{ drupal.jail.name }}/var/www{{ drupal.webRoot|default("") }}'
+      cronUser: '{{ drupal.jail.name }}'
+      apacheUser: '{{ drupal.jail.name }}'
+      apacheLogDir: '{{ jailroot }}/{{ drupal.jail.name }}/var/log/apache2'
+      drushSubkey: .{{ drupal.jail.name }}
+    when: drupal.jail is defined
+
+  - name: Execute Drush Commands
+    shell: drush -y {{ item }}
+    args:
+      chdir: '{{ webRoot }}'
+    with_items:
+      - sql:sync --create-db @{{ drupal.id }}.{{ branch }} @{{ drupal.id }}.{{ destination_branch }}
+      - rsync @{{ drupal.id }}.{{ branch }}:%files/ @{{ drupal.id }}.{{ destination_branch }}:%files -- --chown={{ apacheUser }}:{{ apacheUser }} --safe-links --max-size=20M
+      - cr
+      - updatedb
+      - config-import sync
+
+  - name: Set files ownership
+    file:
+      path: '{{ webRoot }}/files'
+      owner: '{{ apacheUser }}'
+      group: '{{ apacheUser }}'
+      mode: ug+rw
+      recurse: yes
+      follow: no
+
+  tags:
+    - copy_db_and_assets
diff --git a/tasks/main.yml b/tasks/main.yml
index 099cbba..04b85a2 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -89,3 +89,14 @@
         - collect_asset_archive
 
   when: (not excluded_roles or "drupal" not in excluded_roles) and drupal_install_drupal and collect_download is defined and collect_download
+
+- block:
+
+    - name: Copy data from stage to stage
+      include_tasks: copy_data/main.yml
+      with_items: '{{ drupal_settings|default([]) }}'
+      loop_control:
+        loop_var: drupal
+      when: siteproject is defined and drupal.siteproject is defined and siteproject == drupal.siteproject and destination_branch == drupal.src.git.branch
+      tags:
+        - copy_db_and_assets
-- 
GitLab