How can I refer to an Ansible variable in log4j2.xml file

66 Views Asked by At

My goal is to define the directory path where the log files will be placed. This configuration should be done inside log4j2.xml file. The value of this path could be set via an Ansible variable (if set in Ansible tower template's extra variables), if it's not set, I should default to a system property which will be surely set -> sys:log.dir

I've tried the following expressions so far:

1st try:

fileName="{{ pa_logs_dir | default(${sys:log.dir}) }}/log/file.log"

2nd try:

<Properties>
  <Property name="LOG_DIR">${pa_logs_dir:-${sys:log.dir}}</Property>
</Properties>

fileName="${LOG_DIR}/log/file.log"

3rd try:

<Properties>
  <Property name="LOG_DIR">${sys:pa_logs_dir:-${sys:log.dir}}</Property>
</Properties>

fileName="${LOG_DIR}/log/file.log"

The /log/file.log at the and should be the same in both cases.

The 1st try produced an error, the 2nd and the 3rd try compiled successfully, but if I set the pa_logs_dir varable inside the Extra variables of Ansible template, it is not honored, unfortunately.

Any help would be really appreciated, thanks in advance!

0

There are 0 best solutions below