I would like to include some caching functionality via an NGINX inlcude to my production sites, but not on my staging sites. However, I believe if I have the nginx-includes folder with the main site key specified the includes would also be added on subsequent provisions of the staging server. Is there a way to specify the nginx-includes which should be only be applied to production?
Never thought of different nginx-includes per environment. Here are a few ideas you might try.
Jinja conditional. You could let the include file be templated to all environments, but inside the file, wrap all content in if env == 'production'
, like example in Trellis. For non-production, the include would be created as empty. This is a good option if you only have one include that differs by environment.
Adjust nginx_includes_templates_path
. The nginx-includes docs mention that you can customize where Trellis looks for include files, using the nginx_includes_templates_path
variable. You might prefer this option if you have many includes that differ by environment.
trellis/
nginx-includes/
default/
example.com/
production/
example.com/
# trellis/group_vars/all/main.yml
nginx_includes_templates_path: nginx-includes/default
# trellis/group_vars/production/main.yml
nginx_includes_templates_path: nginx-includes/production
The above strategies of 1) Jinja conditional or 2) differing path definition per environment could be adapted to the alternative of child templates (vs. include files).