diff --git a/copy_all_users.yml b/copy_all_users.yml new file mode 100644 index 0000000..9cf5e8c --- /dev/null +++ b/copy_all_users.yml @@ -0,0 +1,21 @@ +--- +- name: Copy user database from a one nextcloud to another + hosts: all + vars: + container_name: "db" + tasks: + - debug: msg="{{ nextcloud_admin_passwd }}" + - name: Backup Postgres necessary table on src + block: + - shell: "docker exec -u postgres {{ container_name }} pg_dump --clean -t public.oc_accounts -t public.oc_users -t public.oc_groups -t public.oc_group_admin -t public.oc_group_user nextcloud > /tmp/nextcloud_backup.sql" + - name: Fetch the SQL dump from src + run_once: yes + fetch: src=/tmp/nextcloud_backup.sql dest=/tmp/ flat=yes + when: inventory_hostname == "nextcloud-src" + - name: Restore Postgres necessary table on dst + block: + - name: Copy the SQL dump to dst + copy: src=/tmp/nextcloud_backup.sql dest=//tmp/ + become: yes + - shell: "docker exec -i -u postgres {{ container_name }} psql nextcloud < /tmp/nextcloud_backup.sql" + when: inventory_hostname == "nextcloud-dst" \ No newline at end of file diff --git a/inventory b/inventory new file mode 100644 index 0000000..3a85377 --- /dev/null +++ b/inventory @@ -0,0 +1,2 @@ +nextcloud-src ansible_host=192.168.1.27 ansible_user=cloudadm ansible_password=cloudadm +nextcloud-dst ansible_host=192.168.1.97 ansible_user=cloudadm ansible_password=cloudadm