Roots Discourse

Pushing or pulling uploads with Trellis


I wanted to share a small playbook I’m using to sync the uploads between different environments (local to staging, local to prod or vice-versa).

Usage is really simple, drop in at the root of Trellis (where the other roles like server.yml are and use it like this:

ansible-playbook uploads.yml -i hosts/staging --extra-vars=" mode=pull"

where staging can be replaced by production depending of the environment you want, is the name of the key in Trellis environment file (the same that you use to deploy a site) and mode is push or pull depending on what you want to do with the uploads. When mode is omitted, it will default to push.

I hope it can be useful to someone! :smile:


Thank you for this! I was using rsync separately, and this is awesome.

I am getting this error:
msg: rsync: link_stat “/Users/btamm/Sites/vm/…/site/web/app/uploads/.” failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-45/rsync/main.c(992) [sender=2.6.9]

I ran this: ansible-playbook uploads.yml -i hosts/production --extra-vars=“ mode=push”

Any ideas?

It can be a couple of things. The most frequent is permissions on some files or network problem. First, check if re-running the same command always give you the error. if not, it may have been a network error.

If you always get the error, add --verbose to the sync options of the playbook like that:

rsync_opts: --exclude=.DS_Store,--verbose

Check if it gives you more info to find the problem.

1 Like

Thanks for this awesome script @louim.

I had the same issue and error message as @btamm. To resolve the errors I had to:

  1. Change remote_user to a valid username (or ensure web_user is set in my environment config)
  2. Change the sync (for push) to src: "{{ project.local_path }}/web/app/uploads/"
  3. (Optional) change the dest (for pull) to the same as #2 for use with pulling uploads

Thank you @cfx! I updated the original gist with {{ project.local_path }} which is a lot better than hardcoding the value.

So useful! Legend. Thanks for taking the time to do this :slight_smile:

What a great concept thank you for posting this.
So if I were on my local box and wanted to pull from production. Is it written like below?

ansible-playbook uploads.yml -i hosts/production --extra-vars=" mode=pull"