diff --git a/playbooks/roles/rsyslog_client/defaults/main.yml b/playbooks/roles/rsyslog_client/defaults/main.yml index 6d8b4ab583..34e78e98f4 100644 --- a/playbooks/roles/rsyslog_client/defaults/main.yml +++ b/playbooks/roles/rsyslog_client/defaults/main.yml @@ -44,6 +44,9 @@ rsyslog_client_udp_port: 514 rsyslog_client_tcp_reception: false rsyslog_client_tcp_port: 514 +# Define the log files list as empty +rsyslog_client_log_files: [] + # Set the `rsyslog_client_user_defined_targets` to define specific log targets. # This option will allow you to define multiple log targets with different templates # and options. The value of this variable is a list of hashes with the following diff --git a/playbooks/roles/rsyslog_client/tasks/rsyslog_client_post_install.yml b/playbooks/roles/rsyslog_client/tasks/rsyslog_client_post_install.yml index abfc2ef3f9..1ddede583f 100644 --- a/playbooks/roles/rsyslog_client/tasks/rsyslog_client_post_install.yml +++ b/playbooks/roles/rsyslog_client/tasks/rsyslog_client_post_install.yml @@ -41,35 +41,6 @@ tags: - rsyslog-client-config -- name: Set fact for combined log files list and found logs - set_fact: - rsyslog_client_log_files: "{{ log_files.stdout_lines | union(rsyslog_client_log_files) }}" - when: > - rsyslog_client_log_files is defined and - log_files | success - tags: - - rsyslog-client-config - -- name: Set fact for found log files list - set_fact: - rsyslog_client_log_files: "{{ log_files.stdout_lines }}" - when: > - rsyslog_client_log_files is not defined and - log_files | success - tags: - - rsyslog-client-config - -- name: Check rsyslog_client_log_files is defined - fail: - msg: > - There were no log files defined in `rsyslog_client_log_files`. Please use that - variable to set the files that you want rsyslog to begin shipping logs for. This - variable is a list that requires the full path to all log files. You can also set - `rsyslog_client_log_dir` which will find all "*.log" files using the path - provided. - when: > - rsyslog_client_log_files is not defined - - name: Write rsyslog config for found log files template: src: "{{ item.src }}" diff --git a/playbooks/roles/rsyslog_client/templates/99-rsyslog.conf.j2 b/playbooks/roles/rsyslog_client/templates/99-rsyslog.conf.j2 index 3248ab5967..be8c89dc8b 100644 --- a/playbooks/roles/rsyslog_client/templates/99-rsyslog.conf.j2 +++ b/playbooks/roles/rsyslog_client/templates/99-rsyslog.conf.j2 @@ -1,5 +1,9 @@ # {{ ansible_managed }} +{% if log_files is defined %} +{% set rsyslog_client_log_files = log_files.stdout_lines | union(rsyslog_client_log_files) %} +{% endif %} + $WorkDirectory {{ rsyslog_client_spool_directory }} $template RFC3164fmt,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%" diff --git a/playbooks/roles/rsyslog_client/templates/os_aggregate_storage.j2 b/playbooks/roles/rsyslog_client/templates/os_aggregate_storage.j2 index 02031a1a88..7e25ae6736 100644 --- a/playbooks/roles/rsyslog_client/templates/os_aggregate_storage.j2 +++ b/playbooks/roles/rsyslog_client/templates/os_aggregate_storage.j2 @@ -1,3 +1,6 @@ +{% if log_files is defined %} +{% set rsyslog_client_log_files = log_files.stdout_lines | union(rsyslog_client_log_files) %} +{% endif %} {% for log_file in rsyslog_client_log_files %} {{ log_file }} {% endfor %}