I think the host_vars directory would be applicable if you had multiple DO droplets…
host_vars/
vars_file_for_droplet_1
vars_file_for_droplet_2
I don’t think host_vars
applies here because @patrickv has only one server (ansible “host”), with multiple sites on that server.
People may have more variability in their customizations to the deploy “build commands” than other parts of trellis, so it is hard to set defaults that people won’t need to adjust. In your case, @patrickv here’s what I would try first. I’m not sure it would work (i.e., untested).
You have one set of build commands that you want run on only one of your sites. I would instruct the build commands definition to get its list of commands from a variable in the wordpress_sites
dictionary, per site. If the list is missing for any given site, just use the default empty list: []
project_pre_build_commands_local: "{{ project.pre_build_commands_local | default([]) }}"
project_local_files: "{{ project.local_files | default([]) }}"
wordpress_sites:
site1.com:
⋮
pre_build_commands_local:
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: npm install
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: bower install
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: gulp --production
local_files:
- name: compiled theme assets
src: "{{ project.local_path }}/web/app/themes/sage/dist"
dest: web/app/themes/sage
site3.com:
⋮
site4.com:
⋮
site5.com:
⋮
To round this out, the approach above works well for someone whose build commands will usually differ per site. Consider the other case, however, in which a person’s build commands will always be the same, but they want to run them for just some of their sites. The approach above would require repeating the same set of commands for multiple sites, which isn’t very DRY. In that case, I’d suggest adding a ternary filter like this (also untested):
pre_build_commands_local:
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: npm install
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: bower install
- path: "{{ project.local_path }}/web/app/themes/sage"
cmd: gulp --production
local_files:
- name: compiled theme assets
src: "{{ project.local_path }}/web/app/themes/sage/dist"
dest: web/app/themes/sage
project_pre_build_commands_local: "{{ project.run_pre_build_commands_local | ternary(pre_build_commands_local, []) }}"
project_local_files: "{{ project.copy_local_files | ternary(local_files, []) }}"
wordpress_sites:
site1.com:
⋮
run_pre_build_commands_local: true
copy_local_files: true
site3.com:
⋮
run_pre_build_commands_local: false
copy_local_files: false
site4.com:
⋮
run_pre_build_commands_local: true
copy_local_files: true
site5.com:
⋮
run_pre_build_commands_local: false
copy_local_files: false
There could be variations on the above. The above keeps your logic in your vars config files, but you I suppose you could make a given build commands task conditional by adding things like when: project.run_pre_build_commands_local
. See how some other tasks in that task list use the when:
conditional.