Skip to content

Instantly share code, notes, and snippets.

@louim

louim/uploads.yml

Last active Sep 17, 2020
Embed
What would you like to do?
Drop-in playbook for Trellis to push and pull uploads from the server to your local machine.
---
- name: Sync uploads between environments
hosts: web
remote_user: "{{ web_user }}"
vars:
project: "{{ wordpress_sites[site] }}"
project_root: "{{ www_root }}/{{ site }}"
tasks:
# ansible-playbook uploads.yml -i hosts/staging --extra-vars="site=example.com mode=push"
- name: Push uploads
synchronize:
src: "{{ project.local_path }}/web/app/uploads/"
dest: "{{ project_root }}/current/web/app/uploads/"
rsync_opts: --exclude=.DS_Store
when: mode is not defined or mode == "push"
# ansible-playbook uploads.yml -i hosts/staging --extra-vars="site=example.com mode=pull"
- name: Pull uploads
synchronize:
src: "{{ project_root }}/current/web/app/uploads/"
dest: "{{ project.local_path }}/web/app/uploads/"
mode: pull
rsync_opts: --exclude=.DS_Store
when: mode is defined and mode == "pull"
@whalesingswee

This comment has been minimized.

Copy link

@whalesingswee whalesingswee commented Jul 4, 2016

Man! Thanks for having this, this made everything complete!

@s3w47m88

This comment has been minimized.

Copy link

@s3w47m88 s3w47m88 commented Nov 6, 2017

Thank you for this Playbook. It worked perfectly after placing it in /trellis/ and executing the commands you specify in the code comments.

I also attempted to include this as a Git Submodule in /trellis/deploy-hooks/sync-uploads-directory but upon running the Playbook I get this error and I don't know why.

TASK [Gathering Facts] *************************************************************************************************************************************** fatal: [site.example.com]: FAILED! => {"failed": true, "msg": "The field 'remote_user' has an invalid value, which includes an undefined variable. The error was: 'web_user' is undefined\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'web_user' is undefined"}

Can you share any insight about this?

@penhtech

This comment has been minimized.

Copy link

@penhtech penhtech commented Apr 30, 2019

Thanks a lot. This is still working great and saving me a lot of time, but just a note for anyone using Kinsta: Using a site with the recommended structure (conforming to the trellis example project) I had to change project_root: "{{ www_root }}/{{ site }}" to just project_root: "{{ www_root }}". If you want to be picky, delete that line entirely and change the two occurrences of "project_root" to "www_root".

@harshblog150

This comment has been minimized.

Copy link

@harshblog150 harshblog150 commented Jul 23, 2019

cool..thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.