-
-
Save cfxd/481884e980c61ac99150 to your computer and use it in GitHub Desktop.
Database sync Ansible playbook run with ansible-playbook sync.yml -i hosts/sync -e "src=development dest=staging site=cfx"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[development] | |
127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/Users/cfx/Sites/trellis/.vagrant/machines/default/virtualbox/private_key | |
[staging] | |
my-staging.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Dump database | |
hosts: "{{ src }}" | |
remote_user: "{{ web_user }}" | |
gather_facts: false | |
vars: | |
project: "{{ wordpress_sites[site] }}" | |
project_root: "{{ www_root }}/{{ site }}" | |
tasks: | |
- name: Dump local database | |
mysql_db: | |
state=dump | |
name={{ project.env.db_name }} | |
target={{ project_root }}/current/.sql/{{ src }}.sql | |
login_user={{ project.env.db_user }} | |
login_password={{ project.env.db_password }} | |
- name: Import database | |
hosts: "{{ dest }}" | |
remote_user: "{{ web_user }}" | |
gather_facts: false | |
vars: | |
project: "{{ wordpress_sites[site] }}" | |
project_root: "{{ www_root }}/{{ site }}" | |
tasks: | |
- name: Copy database dump to destination | |
copy: src="{{ project.local_path }}/.sql/{{ src }}.sql" dest="{{ project_root }}/current/.sql/{{ src }}.sql" | |
- name: Import source database into destination | |
mysql_db: login_user="{{ project.env.db_user }}" login_password="{{ project.env.db_password }}" state=import name={{ project.env.db_name }} target="{{ project_root }}/current/.sql/{{ src }}.sql" | |
- name: Search & replace database | |
command: wp search-replace 'http://cfx.dev' '{{ project.env.wp_home }}' --path="{{ project_root }}/current/web/wp" | |
# copy actually needs to be done via SSH, even if src is local vm | |
# wp search-replace needs to get src env.wp_home and needs to get path dynamically |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment