Roots Discourse

Conditional Hook

I am trying to set up a hook that only fires on my production env to clear the cache.

Could you provide more details on how to do this?

I noticed there is a when: keyword in the .yml files of some of the hooks. Is there where I would put a conditional?

How would I change the code below to run this hook conditionally?

- name: Clear Kinsta cache
  uri:
    url: "{{ site_env.wp_home }}/kinsta-clear-cache-all/"
    method: GET
    changed_when: {{ site_env.wp_home }} === 'www.myproductiondomain.com'

The third include file, deploy-hooks/sites/{{ site }}-build-after.yml , demonstrates how you could use a {{ site }} variable to include a file based on the name of the site being deployed, e.g., example.com-build-after.yml

https://roots.io/docs/trellis/master/deployments/#custom-tasks