forked from hashbangcode/vlad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hashbangcode#292 from wizonesolutions/feature-pant…
…heon-import Add support for importing Pantheon sites.
- Loading branch information
Showing
8 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
vlad_guts/playbooks/roles/pantheon_import_site/defaults/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
# Pantheon Import settings | ||
|
||
vlad_pantheon_import_site: false | ||
vlad_pantheon_import_site_email: '' | ||
vlad_pantheon_import_site_password: '' | ||
vlad_pantheon_import_site_site: '' | ||
vlad_pantheon_import_site_env: '' | ||
vlad_pantheon_import_site_include_code: false | ||
vlad_pantheon_import_site_include_db: true | ||
vlad_pantheon_import_site_include_files: true | ||
|
||
# @todo: Figure out an easy way, or document an Ansible command — possibly with tags — to update the imported Pantheon site without having to rebuild the entire VM. |
6 changes: 6 additions & 0 deletions
6
vlad_guts/playbooks/roles/pantheon_import_site/tasks/import_code.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: pantheon_import_site | code | Look up Git URL | ||
command: /usr/local/bin/terminus site connection-info --json --site='{{ vlad_pantheon_import_site_site }}' --env='{{ vlad_pantheon_import_site_env }}' | ||
register: vlad_pantheon_import_site_connection_info_output | ||
- set_fact: | ||
vlad_pantheon_import_site_site_info: "{{ vlad_pantheon_import_site_connection_info_output.stdout|from_json }}" |
32 changes: 32 additions & 0 deletions
32
vlad_guts/playbooks/roles/pantheon_import_site/tasks/import_db.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# If they halted or restarted the VM before running provisioning, Vlad itself will have overwritten vladdb.sql.gz. | ||
# Move it to a separate location instead of deleting it outright. | ||
- name: db | Check for existing vladdb.sql.gz | ||
stat: path=/var/www/site/vlad_aux/db_io/halt_destroy/vladdb.sql.gz | ||
register: vlad_pantheon_import_site_evdb | ||
ignore_errors: true | ||
|
||
- name: db | Back up existing vladdb.sql.gz | ||
command: mv -f /var/www/site/vlad_aux/db_io/halt_destroy/vladdb.sql.gz /var/www/site/vlad_aux/db_io/halt_destroy/vladdb_pantheon_import_site_backup.sql.gz | ||
when: vlad_pantheon_import_site_evdb is defined and vlad_pantheon_import_site_evdb.stat.exists == True | ||
|
||
- name: db | Download latest database backup from Pantheon | ||
command: terminus site backups get --site="{{ vlad_pantheon_import_site_site }}" --env="{{ vlad_pantheon_import_site_env }}" --element=db --latest --to=/var/www/site/vlad_aux/db_io/halt_destroy/pantheon_import_site.sql.gz | ||
args: | ||
creates: /var/www/site/vlad_aux/db_io/halt_destroy/pantheon_import_site.sql.gz | ||
|
||
- name: db | Copy downloaded database to vladdb.sql.gz so mysql role will import it | ||
command: cp /var/www/site/vlad_aux/db_io/halt_destroy/pantheon_import_site.sql.gz /var/www/site/vlad_aux/db_io/halt_destroy/vladdb.sql.gz | ||
args: | ||
creates: /var/www/site/vlad_aux/db_io/halt_destroy/vladdb.sql.gz | ||
|
||
# If we already have MySQL from a previous run, then clear the DB so that the new backup will get imported later. | ||
- name: db | Check if mysql works | ||
stat: path=/usr/bin/mysql | ||
ignore_errors: true | ||
register: vlad_pantheon_import_site_haz_mysql | ||
|
||
- name: db | Drop vladdb database | ||
mysql_db: name=vladdb state=absent login_user='{{ dbuser }}' login_password='{{ dbpass }}' | ||
sudo: yes | ||
when: vlad_pantheon_import_site_haz_mysql.stat.exists is defined and vlad_pantheon_import_site_haz_mysql.stat.exists == True |
20 changes: 20 additions & 0 deletions
20
vlad_guts/playbooks/roles/pantheon_import_site/tasks/import_files.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- name: files | Download latest files backup from Pantheon | ||
command: terminus site backups get --site="{{ vlad_pantheon_import_site_site }}" --env="{{ vlad_pantheon_import_site_env }}" --element=files --latest --to=/var/www/site/vlad_aux/pantheon_import_site_files.tar.gz | ||
args: | ||
creates: /var/www/site/vlad_aux/pantheon_import_site_files.tar.gz | ||
|
||
- name: files | Remove old file directory | ||
file: path=/var/www/site/docroot/sites/default/files state=absent recurse=yes | ||
when: vlad_pantheon_import_site_files_stat is defined and vlad_pantheon_import_site_files_stat.stat.exists == True | ||
|
||
- name: files | Expand downloaded archive | ||
unarchive: | ||
src: /var/www/site/vlad_aux/pantheon_import_site_files.tar.gz | ||
dest: /var/www/site/docroot/sites/default/ | ||
copy: no # This is an in-VM unarchive operation. | ||
creates: /var/www/site/docroot/sites/default/files_{{ vlad_pantheon_import_site_env }} | ||
|
||
- name: files | Rename files_<ENV> directory to just files | ||
command: mv '/var/www/site/docroot/sites/default/files_{{ vlad_pantheon_import_site_env }}' /var/www/site/docroot/sites/default/files | ||
args: | ||
creates: /var/www/site/docroot/sites/default/files |
8 changes: 8 additions & 0 deletions
8
vlad_guts/playbooks/roles/pantheon_import_site/tasks/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# Load variable file based on the OS type, or a default if not found. | ||
- include_vars: "{{ item }}" | ||
with_items: | ||
- "all.yml" | ||
|
||
- include: pantheon_import_site.yml | ||
tags: pantheon_import |
43 changes: 43 additions & 0 deletions
43
vlad_guts/playbooks/roles/pantheon_import_site/tasks/pantheon_import_site.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# Authenticate to Pantheon CLI. Don't do anything else if it | ||
# fails, but do ignore errors (this doesn't need to halt provisioning). | ||
# @todo: Run a terminus auth whoami first and don't mark anything changed if we are already logged in. | ||
- name: Log in to Pantheon | ||
command: /usr/local/bin/terminus auth login "{{ vlad_pantheon_import_site_email }}" --password='{{ vlad_pantheon_import_site_password }}' | ||
register: vlad_pantheon_auth_success | ||
ignore_errors: yes | ||
|
||
- name: Check if docroot/sites/default folder exists | ||
stat: path=/var/www/site/docroot/sites/default | ||
register: vlad_pantheon_import_site_sd_stat | ||
when: vlad_pantheon_import_site_include_files == True and vlad_pantheon_auth_success.rc == 0 | ||
ignore_errors: yes | ||
|
||
- name: files | Check if downloaded file archive already exists | ||
stat: path=/var/www/site/vlad_aux/pantheon_import_site_files.tar.gz | ||
register: vlad_pantheon_import_site_files_stat | ||
when: vlad_pantheon_import_site_sd_stat is defined and vlad_pantheon_import_site_sd_stat.stat.exists == True and vlad_pantheon_import_site_include_files == True and vlad_pantheon_auth_success.rc == 0 | ||
ignore_errors: yes | ||
|
||
- include: import_files.yml | ||
when: vlad_pantheon_import_site_include_files is defined and vlad_pantheon_import_site_include_files == True and vlad_pantheon_import_site_files_stat is defined and vlad_pantheon_import_site_files_stat.stat.exists == False | ||
|
||
- name: db | Check if database backup already exists | ||
stat: path=/var/www/site/vlad_aux/db_io/halt_destroy/pantheon_import_site.sql.gz | ||
register: vlad_pantheon_import_site_db_exists | ||
when: vlad_pantheon_import_site_include_db == True and vlad_pantheon_auth_success.rc == 0 | ||
ignore_errors: yes | ||
|
||
# This command is copied from the mysql role because we run before it. | ||
- name: db | Ensure vlad_aux/db_io directories exist | ||
file: | ||
path: /var/www/site/vlad_aux/{{ item }} | ||
state: directory | ||
mode: 0777 | ||
with_items: | ||
- db_io | ||
- db_io/halt_destroy | ||
sudo: true | ||
|
||
- include: import_db.yml | ||
when: vlad_pantheon_import_site_include_db is defined and vlad_pantheon_import_site_include_db == True and vlad_pantheon_import_site_db_exists is defined and vlad_pantheon_import_site_db_exists.stat.exists == False |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains 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