I am having a problem with defining a string variable in Ansible (v2.9.9)
The string I want to define (for the geerlingguy.apache role):
apache_global_vhost_settings: |
LogFormat “<%%JSON:httpd_access%%> { "time": "%{%Y}t" }” combined
CustomLog logs/access_log combined
This doesn’t work and I am getting the following error message: template error while templating string: Encountered unknown tag ‘Y’… String: LogFormat
It basically comes down to the following part: "%{%Y}t" }
How can I achieve the specified string in Ansible ? I tried escaping several properties however wasn’t able to find out a solution.
I am having a problem with defining a string variable in Ansible (v2.9.9)
The string I want to define (for the geerlingguy.apache role):
apache_global_vhost_settings: |
LogFormat "<%%JSON:httpd_access%%> { \"time\": \"%\{%Y}t\" }" combined
CustomLog logs/access_log combined
This doesn't work and I am getting the following error message:
/template error while templating string: Encountered unknown tag 'Y'.. String: LogFormat// <snip>/
It basically comes down to the following part: \"%\{%Y}t\" }
How can I achieve the specified string in Ansible ? I tried escaping several properties however wasn't able to find out
a solution.
Well, how should the expected LogFormat line look like?
By the var name I guess you're using the jeff geerling's apache role?
I use that too and also ran into this issue.
You need to escape the jinja looking part.
My snippet:
I am having a problem with defining a string variable in Ansible (v2.9.9)
The string I want to define (for the geerlingguy.apache role):
apache_global_vhost_settings: |
LogFormat “<%%JSON:httpd_access%%> { "time": "%{%Y}t" }” combined
CustomLog logs/access_log combined
This doesn’t work and I am getting the following error message:
/template error while templating string: Encountered unknown tag ‘Y’… String: LogFormat// /
It basically comes down to the following part: "%{%Y}t" }
How can I achieve the specified string in Ansible ? I tried escaping several properties however wasn’t able to find out
a solution.
Well, how should the expected LogFormat line look like?
(I put it on pastebin since the full string can be messed up in e-mail)
But to get there I first tried to add the following line to be part of the Ansible variable (which throws the error already): LogFormat “<%%JSON:httpd_access%%> { "time": "%{%Y-%m-%dT%H:%M:%S%z}t" }” combined
By the var name I guess you’re using the jeff geerling’s apache role?
I use that too and also ran into this issue.
You need to escape the jinja looking part.
My snippet:
It may be even easier if you wrap the entire thing in 'raw'. This
should be fine as you don't use jinja inside that LogFormat statement.
Hence the value will be just in the YAML as-is, i.e. easier to debug:
Both methods yield the same result, so use which one is easier in your case.
IIRC I didn't use 'raw' because it messed up the yaml syntax
highlighting in my editor.