forked from hamedb89/trellis-db-push-and-pull
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-push.yml
35 lines (30 loc) · 1.2 KB
/
db-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
- name: Push Database from development to "{{ env }}"
hosts: web:&{{ env }}
remote_user: "{{ web_user }}"
vars:
project_root: "{{ www_root }}/{{ site }}"
project_web_dir: "{{ project_root }}/current"
url_from: "{{ hostvars.vagrant.wordpress_sites.values().0.site_hosts.0.canonical }}"
to: "{{hostvars[env]}}"
url_to: "{{to.wordpress_sites.values().0.site_hosts.0.canonical}}"
tasks:
- name: create db backup on development with wp-cli
delegate_to: vagrant
command: wp db export db.sql
args:
chdir: "{{ project_web_dir }}"
- name: copy db.sql to "{{env}}"
copy:
src: ../site/db.sql
dest: "{{project_web_dir}}/db.sql"
- name: import db backup on "{{ env }}"
command: wp db import db.sql --allow-root
args:
chdir: "{{project_web_dir}}"
# - command: wp search-replace hostvars[groups['development'][0]].wordpress_sites[site].site_hosts.0.canonical hostvars[groups[env][0]].wordpress_sites[site].site_hosts.0.canonical
- name: search and replace from "{{url_from}}" to "{{url_to}}"
command: wp search-replace '(www.)?{{url_from}}' '{{url_to}}' --allow-root --regex
args:
chdir: "{{project_web_dir}}"
tags: ['search-replace']