Skip to content

Making Varnish template handling more flexible. #1485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
- [SSL](/roles/debian/ssl)
- [sudo config](/roles/debian/sudo_config)
- [Swap](/roles/debian/swap)
- [varnish-config](/roles/debian/varnish_config)
- [varnish_config](/roles/debian/varnish_config)
- [wazuh](/roles/debian/wazuh)
- [Init role](/roles/_init)
- ["Meta" roles that group individual roles together.](/roles/_meta)
Expand Down
21 changes: 19 additions & 2 deletions docs/roles/debian/varnish_config.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# varnish-config
Installs and configures Varnish, with 6.4 being the default version. Depends on geerlingguy.varnish which does the setup bit, varnish-config handles the default.vcl file.
# varnish_config
Installs and configures Varnish, with 6.4 being the default version. Depends on `geerlingguy.varnish` which does the setup bit, `varnish_config` handles the `default.vcl` file.

You can provide a template override in two locations, they will be checked in this order:
* `templates` in the same directory as your server's playbook
* `files/templates` in your `ce-provision-config` repository

If no alternative is found, the `default.vcl.j2` template provided with this role is used. By default the override template is expected to be named `default.vcl.j2`, however if you set `varnish_config.template_filename` you can change this. For example, if you place a template at `files/templates/my-app.v1.vcl.j2` in your config repository, you need to set the variable as follows, note *without* the `.j2` which is implicit:

```yaml
varnish_config:
template_filename: my-app.v1.vcl
```

This behaviour allows you to manage different Varnish templates for different applications. You may of course provide your own variables in the `varnish_config` dictionary for your custom template.

<!--TOC-->
<!--ENDTOC-->

Expand All @@ -23,6 +37,9 @@ varnish_config:
strip_cookies: (^|;\s*)(_[_a-z]+|has_js|AWSELB|cookie-agreed)=[^;]*
# List of upstream proxies we trust to set X-Forwarded-For correctly, use either CIDR or list all the IPs.
upstream_proxies: []
# Provide an alternative filename if you are providing a template.
template_filename: default.vcl

```

<!--ENDROLEVARS-->
1 change: 1 addition & 0 deletions docs/roles/debian/wazuh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Supports standalone managers, scaled out services and agent installation (defaul
```yaml
---
wazuh:
path: wazuh
#roles_directory: "/path/to/roles" # defaults to /home/controller/.ansible/roles/wazuh-ansible
branch: "v4.7.2" # wazuh-ansible git branch to checkout - not to be confused with wazuh_version!
# Agent variables, installed locally by default
Expand Down
21 changes: 19 additions & 2 deletions roles/debian/varnish_config/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# varnish-config
Installs and configures Varnish, with 6.4 being the default version. Depends on geerlingguy.varnish which does the setup bit, varnish-config handles the default.vcl file.
# varnish_config
Installs and configures Varnish, with 6.4 being the default version. Depends on `geerlingguy.varnish` which does the setup bit, `varnish_config` handles the `default.vcl` file.

You can provide a template override in two locations, they will be checked in this order:
* `templates` in the same directory as your server's playbook
* `files/templates` in your `ce-provision-config` repository

If no alternative is found, the `default.vcl.j2` template provided with this role is used. By default the override template is expected to be named `default.vcl.j2`, however if you set `varnish_config.template_filename` you can change this. For example, if you place a template at `files/templates/my-app.v1.vcl.j2` in your config repository, you need to set the variable as follows, note *without* the `.j2` which is implicit:

```yaml
varnish_config:
template_filename: my-app.v1.vcl
```

This behaviour allows you to manage different Varnish templates for different applications. You may of course provide your own variables in the `varnish_config` dictionary for your custom template.

<!--TOC-->
<!--ENDTOC-->

Expand All @@ -23,6 +37,9 @@ varnish_config:
strip_cookies: (^|;\s*)(_[_a-z]+|has_js|AWSELB|cookie-agreed)=[^;]*
# List of upstream proxies we trust to set X-Forwarded-For correctly, use either CIDR or list all the IPs.
upstream_proxies: []
# Provide an alternative filename if you are providing a template.
template_filename: default.vcl

```

<!--ENDROLEVARS-->
4 changes: 3 additions & 1 deletion roles/debian/varnish_config/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ varnish_config:
redirect_host_destination: ""
strip_cookies: (^|;\s*)(_[_a-z]+|has_js|AWSELB|cookie-agreed)=[^;]*
# List of upstream proxies we trust to set X-Forwarded-For correctly, use either CIDR or list all the IPs.
upstream_proxies: []
upstream_proxies: []
# Provide an alternative filename if you are providing a template.
template_filename: default.vcl
8 changes: 6 additions & 2 deletions roles/debian/varnish_config/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
- name: Copy Varnish default VCL.
ansible.builtin.template:
src: "default.vcl.j2"
src: "{{ item }}"
dest: "{{ varnish_config_path }}/default.vcl"
owner: root
group: root
mode: 0644
with_first_found:
- "{{ playbook_dir }}/templates/{{ varnish_config.template_filename }}.j2"
- "{{ _ce_provision_base_dir }}/config/files/templates/{{ varnish_config.template_filename }}.j2"
- "default.vcl.j2"
notify:
- reload systemd
- restart varnish
- restart varnish
1 change: 1 addition & 0 deletions roles/debian/wazuh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Supports standalone managers, scaled out services and agent installation (defaul
```yaml
---
wazuh:
path: wazuh
#roles_directory: "/path/to/roles" # defaults to /home/controller/.ansible/roles/wazuh-ansible
branch: "v4.7.2" # wazuh-ansible git branch to checkout - not to be confused with wazuh_version!
# Agent variables, installed locally by default
Expand Down