ajout playbook creation site
[lhc/ansible.git] / tasks / restore_to_vm.yml
index 4998bc2..653b87e 100644 (file)
@@ -1,13 +1,30 @@
 ---
-# - name: Clean nextcloud restore dir content
-#   become_user: "{{ nextcloud_websrv_user }}"
-#   become: true
-#   ansible.builtin.file:
-#     path: "{{ item }}"
-#     state: absent
-#   loop: 
-#     - "{{ nextcloud_tmp_path }}"
-#     - "{{ nextcloud_webroot }}/data"
+# chown -R www-data: /opt/nuage/backups/clavette-gre
+# sudo -u postgres psql
+# DROP DATABASE nextcloud;
+# CREATE DATABASE nextcloud WITH OWNER=php_mig_nuage;
+# GRANT ALL ON SCHEMA public TO php_mig_nuage WITH GRANT OPTION;
+# GRANT USAGE,CREATE ON SCHEMA public TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_namespace TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_collation TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_index TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_attrdef TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_description TO php_mig_nuage;
+# GRANT SELECT ON TABLE pg_settings TO php_mig_nuage;
+# GRANT SELECT ON pg_database TO php_mig_nuage;
+# exit
+# sudo -u php_mig_nuage pg_restore -F c -Oxc --if-exists -d nextcloud /opt/nuage/backups/clavette-gre/dump.pgc
+
+
+- name: Clean nextcloud restore dir content
+  become_user: "{{ nextcloud_websrv_user }}"
+  become: true
+  ansible.builtin.file:
+    path: "{{ item }}"
+    state: absent
+  loop:
+    - "{{ nextcloud_tmp_path }}"
+    - "{{ nextcloud_webroot }}/data"
 
 - name: Recreate nextcloud restore dir # necessite le paquet acl installé
   become_user: "{{ nextcloud_websrv_user }}"
   ansible.builtin.file:
     path: "{{ item }}"
     state: directory
-  loop: 
+  loop:
     - "{{ nextcloud_tmp_path }}"
-    - "{{ nextcloud_webroot }}/data"
 
-- name: Copy files from ansible controller to vm host
-  become_user: "{{ nextcloud_websrv_user }}"
-  become: true
-  ansible.builtin.copy:
-    src: "{{ nextcloud_tmp_path }}/"
-    dest: "{{ nextcloud_tmp_path }}/"
+- name: Copy files from ansible controller to vm host
+  become_user: "{{ nextcloud_websrv_user }}"
+  become: true
+  ansible.builtin.copy:
+    src: "{{ nextcloud_tmp_path }}/"
+    dest: "{{ nextcloud_tmp_path }}/"
 
-# - name: Extract nc data archive
-#   become_user: "{{ nextcloud_websrv_user }}"
-#   become: true
-#   ansible.builtin.unarchive:
-#     src: "{{ nextcloud_tmp_path }}/data.tar.gz"
-#     dest: "{{ nextcloud_webroot }}/data"
+- name: Add read permissions to data backups files
+  become: true
+  become_user: root
+  ansible.builtin.file:
+    path: "{{ nextcloud_backup_path }}"
+    owner: "{{ nextcloud_websrv_user }}"
+    group: "{{ nextcloud_websrv_user }}"
+    state: directory
+    recurse: true
+    mode: '755' # or 'u=rw,g=r,o=r'
+
+- name: Créer un lien symbolique vers le dossier data backups
+  become_user: "{{ nextcloud_websrv_user }}"
+  become: true
+  ansible.builtin.file:
+    src: "{{ nextcloud_backup_path }}/data"
+    dest: "{{ nextcloud_webroot }}/data"
+    owner: "{{ nextcloud_websrv_user }}"
+    group: "{{ nextcloud_websrv_user }}"
+    state: link
+    follow: false
 
 - name: Stop webserver service
   become: true
@@ -55,7 +86,8 @@
     name: "{{ nextcloud_db_name }}"
     state: "{{ item }}"
     owner: "{{ nextcloud_websrv_user }}"
-    target: "{{ nextcloud_tmp_path }}/dump.sql"
+    target: "{{ nextcloud_tmp_path }}/dump.pgc"
+    target_opts: "-F c -Oxc --if-exists"
   loop:
     - absent
     - present
 # - name: Restore psql dump # noqa : command-instead-of-module
 #   become: true
 #   become_user: postgres
-#   ansible.builtin.command: "pg_restore -c -F c -O -x -d {{ nextcloud_db_name }} {{ nextcloud_tmp_path }}/dump.pgc"
+#   ansible.builtin.command: "pg_restore -F c -Oxc --if-exists -d {{ nextcloud_db_name }} {{ nextcloud_tmp_path }}/dump.pgc"
 
-- name: Update data fingerprint post db restore # noqa : command-instead-of-module
+- name: Create vm nextcloud config
   become_user: "{{ nextcloud_websrv_user }}"
   become: true
-  ansible.builtin.command: './console maintenance:data-fingerprint'
-  args:
-    chdir: "{{ nextcloud_webroot }}"
+  ansible.builtin.template:
+    src: templates/vm_config_template.j2
+    dest: "{{ nextcloud_webroot }}/config/vm.config.php"
+    owner: "{{ nextcloud_websrv_user }}"
+    group: "{{ nextcloud_websrv_user }}"
+    mode: '640' # or u=rwx,g=r,o=
 
-- name: create nextcloud config
+- name: Create sigle nextcloud config
   become_user: "{{ nextcloud_websrv_user }}"
   become: true
   ansible.builtin.template:
-    src: templates/config_template.j2
-    dest: "{{ nextcloud_webroot }}/config/config.php"
+    src: templates/sigle_config_template.j2
+    dest: "{{ nextcloud_webroot }}/config/sigle.config.php"
     owner: "{{ nextcloud_websrv_user }}"
     group: "{{ nextcloud_websrv_user }}"
     mode: '640' # or u=rwx,g=r,o=
 
+- name: Update data fingerprint post db restore # noqa : command-instead-of-module
+  become_user: "{{ nextcloud_websrv_user }}"
+  become: true
+  ansible.builtin.command: './console maintenance:data-fingerprint'
+  args:
+    chdir: "{{ nextcloud_webroot }}"
+
 - name: Deactivate nextcloud maintenance mode # noqa : command-instead-of-module
   become_user: "{{ nextcloud_websrv_user }}"
   become: true
   when: "'Nextcloud is already latest version' not in nc_upgrade_result.stdout_lines"
   block:
 
-    - name: Launch some occ cleaning command
+    - name: Launch some occ cleaning command # noqa : command-instead-of-module
       become_user: "{{ nextcloud_websrv_user }}"
       become: true
       ansible.builtin.command: "./console { command }}"