Skip to content

Commit 7a10f76

Browse files
Use !unsafe when defining logging template
Instead of using the ugly space workaround to stop Ansible from interpreting `{%` as a Jinja command we can use !unsafe when declaring the variable, and no templating will take place.
1 parent e6a362b commit 7a10f76

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ services. You probably want the same settings across all services, so these
162162
variables exist to make your life easier:
163163

164164
```yaml
165-
# Note the space here----▼
166-
kea_logging_pattern: "%D{ %Y-%m-%d %H:%M:%S.%q } %-5p [%c/%i.%t] %m\n"
165+
# NOTE: !unsafe here----▼
166+
kea_logging_pattern: !unsafe "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i.%t] %m\n"
167167
kea_logging_severity: "INFO"
168168
kea_logging_debuglevel: 0
169169
kea_logging_maxsize: 10485760 # 10 MB
@@ -173,10 +173,10 @@ kea_logging_maxver: 3
173173
Unless you change the `kea_logging_raw_*` variable this will set up logging at
174174
the INFO level both to `stdout` and to a log file with automatic rotation when
175175
it reaches 10MB in size and it will keep 2 files in history before they are
176-
deleted. The only thing to be wary of here is the space in the `{ %` pointed out
177-
above. This was necessary to do because `{%` is a special command in jinja which
178-
makes the templating fail. Just be careful with that in case you want to change
179-
the pattern.
176+
deleted. The only thing to take note of here is the [`!unsafe`][9] keyword used
177+
in the `kea_logging_pattern`. This is used to get around Ansible otherwise
178+
trying to interpret `{%` as a special jinja2 templating command. Just be careful
179+
to keep that in case you want to change the pattern.
180180

181181
However, like in the [subnet](#subnets) case discussed above we allow you to
182182
pipe your own custom settings directly to the templating. Take a look in the
@@ -214,3 +214,4 @@ Only the sky and your sanity is the limit here, so go wild and use the
214214
[6]: https://kea.readthedocs.io/en/latest/arm/logging.html
215215
[7]: https://github.com/JonasAlfredsson/docker-kea#docker-network-mode
216216
[8]: https://kea.readthedocs.io/en/latest/arm/intro.html
217+
[9]: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_advanced_syntax.html#unsafe-or-raw-strings

defaults/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ kea_ctrl_agent_port: 8000
9191
# initial variables will affect all instances unless you change any of the
9292
# "kea_logging_raw_*" variables.
9393
#
94-
# Note the space here----▼ This is to not trip jinja templating with "{%".
95-
kea_logging_pattern: "%D{ %Y-%m-%d %H:%M:%S.%q } %-5p [%c/%i.%t] %m\n"
94+
# NOTE: !unsafe here----▼ This is to not trip jinja templating with "{%".
95+
kea_logging_pattern: !unsafe "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i.%t] %m\n"
9696
kea_logging_severity: "INFO"
9797
kea_logging_debuglevel: 0
9898
kea_logging_maxsize: 10485760 # 10 MB

0 commit comments

Comments
 (0)