Multiple Versons of Sage in One Box -- build-before.yml

I’ve set up Trellis/Bedrock/Sage and I have everything working smoothly with local and staging environments, including building theme assets during deploy and pushing to the server.

I’d like to be able to do this with multiple versions of the sage theme. I thought about doing this by overriding the build-before.yml on a site-specific basis. This is my first time working with Ansible so I’m somewhat blindly following the advice of the community. My current attempt at overriding build-before.yml isn’t working. I’d like to avoid having to set this action on every site and only override when needed. Is what I’m trying to do possible?

  website:
    site_hosts:
      - canonical: website.example.com
    local_path: ../www/website # path targeting local Bedrock site directory (relative to Ansible root)
    repo: git@bitbucket.org:snazzycreative/website.git # replace with your Git repo URL
    branch: master
    multisite:
      enabled: false
    ssl:
      enabled: true
      provider: letsencrypt
    cache:
      enabled: false
    deploy_build_before:
      - "{{ playbook_dir }}/deploy-hooks/build-before-sage8.yml"

Thanks!

Remove your deploy_build_before addition to wordpress_sites.yml.

Add to group_vars/all/main.yml:

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

Then:

deploy-hooks/<site-name>-build-before.yml

PS. website in the config you posted above needs to be an actual site name

1 Like

Thanks Ben. This works well.

Is there a way to default to the main build-before.yml if {{ site }}=build-before.yml doesn’t exist?

Thanks for the tip on the site name. I wiped out specifics in my snippet before posting.

I finally got around to figuring this out. I now have a default build-before.yml and can override said default by adding a new variable to the wordpress_site.

Being new to Ansible, I didn’t know how to access the variable.

I hope this is of use to someone else.

group_vars/all/main.yml:

deploy_build_before:
  - "{{ playbook_dir }}/deploy-hooks/build-before-{{ project.theme | default('sage9') }}.yml"

group_vars/staging/wordpress_sites/yml

  example.com:
    site_hosts:
      - canonical: example.com
    local_path: ../site
    repo: git@bitbucket.org:snazzycreative/example.git
    branch: master
    theme: sage8
    multisite:
      enabled: false
    ssl:
      enabled: true
      provider: letsencrypt
    cache:
      enabled: false
2 Likes