Deploy_build_before for multiple site boxes


So, for boxes with multiple sites…
I have some sites using grunt and also with some other slight requirements for deployment, and they all have different theme names at least.

Here’s what I ended up doing…

In deploy.yml, simply add a -{{ site }} to the deploy_build_before path and create your different build_before files accordingly.

May be obvious but hopefully will help someone.


Good idea! Never thought about this.



  • Edit deploy.yml
    deploy_build_before: "{{ playbook_dir }}/deploy-hooks/{{ site }}-build-before.yml"
  • $ cp deploy-hooks/build-before.yml deploy-hooks/[]-build-before.yml

(r)sync of theme dist

With latest changes to Trellis hook system,
this would be now added to the hooks list in ‘roles/deploy/defaults.yml’:

  - "{{ playbook_dir }}/deploy-hooks/build-before.yml"
  - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-before.yml" # <- this

Trying to install a plugin only for remote server

I use Trellis with multi sites but I have the following structure which I personally prefer.

Instead of prefixing the hook with site I use sub-folders in deploy-hooks depending on what hook it is.

  - "{{ playbook_dir }}/deploy-hooks/build-before/{{ site }}.yml"

  - "{{ playbook_dir }}/deploy-hooks/build-after/{{ site }}.yml"
  # - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-after.yml"

  - "{{ playbook_dir }}/deploy-hooks/finalize-before/{{ site }}.yml"

  - "{{ playbook_dir }}/deploy-hooks/finalize-after/{{ site }}.yml"

so when adding a new site I simply create or depending on environment.


I just noticed in

that the hooks are defined in group_vars/all/deploy-hooks.yml.
Is this a better place because it interferes less with existing trellis files?


@strarsis yes, Trellis has changed since my original post here, that is the best way to go about it now.
in group_vars/all/deploy-hooks.yml

  - "{{ playbook_dir }}/deploy-hooks/{{ site }}-build-before.yml"

…or however you prefer to structure the filenames. You could put them in site directories like:

  - "{{ playbook_dir }}/deploy-hooks/{{ site }}/build-before.yml"

I realize another year has gone by, just posting this for anyone that might find it. There’s now instructions in the trellis docs for this:


Hey, I’ve set this up and it’s successfully looking for the right build file for each site’s deploy, however I’m getting an error that “deploy_helper is undefined”. Guessing this is referring to {{ deploy_helper.new_release_path }}.

How do I pass this variable onto each build-before file?


Please always share your code/what you modified when looking for help.

Are you using the right hook name? deploy_before won’t work but deploy_build_before will work.


Thanks that’s it. I had incorrectly copied deploy_before from the docs, but I see the correct hook is in that post above, which I should’ve copied…