Fix remote logging template
Splitted functionality, one template for generating remote syslog targets and another for streaming the user specifed log files in syslog format. This avoids duplcate targets when the role is invoked mutiple times against a host when installing services. Change-Id: I53e2faf69c0446bea9738a66ee8585e8d795cf52
This commit is contained in:
parent
3e5e80ef0b
commit
705b264df2
@ -74,7 +74,19 @@
|
||||
notify:
|
||||
- restart rsyslog
|
||||
|
||||
- name: Write rsyslog target file
|
||||
- name: Write rsyslog config for remote logging
|
||||
template:
|
||||
src: "remote-logging.j2"
|
||||
dest: "/etc/rsyslog.d/51-remote-logging.conf"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
when: (rsyslog_client_all_log_files | length) > 0
|
||||
tags:
|
||||
- rsyslog_client-config
|
||||
notify:
|
||||
- restart rsyslog
|
||||
|
||||
- name: Write rsyslog config for converting logs into syslog messages
|
||||
template:
|
||||
src: "99-rsyslog.conf.j2"
|
||||
dest: "/etc/rsyslog.d/{{ rsyslog_client_config_name }}"
|
||||
|
@ -1,49 +1,5 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
$WorkDirectory {{ rsyslog_client_spool_directory }}
|
||||
$template RFC3164fmt,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%"
|
||||
|
||||
{% if groups['rsyslog_all'] is defined and groups['rsyslog_all'] %}
|
||||
# Log shipment rsyslog target servers
|
||||
{% for server in groups['rsyslog_all'] %}
|
||||
$ActionQueueFileName {{ server }}
|
||||
$ActionQueueSaveOnShutdown on
|
||||
$ActionQueueType LinkedList
|
||||
$ActionResumeRetryCount 250
|
||||
{% if rsyslog_client_tcp_reception == true %}
|
||||
*.* @@{{ hostvars[server]['ansible_host'] }}:{{ rsyslog_client_tcp_port }};RFC3164fmt
|
||||
{% endif %}
|
||||
{% if rsyslog_client_udp_reception == true %}
|
||||
*.* @{{ hostvars[server]['ansible_host'] }}:{{ rsyslog_client_udp_port }};RFC3164fmt
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if rsyslog_client_user_defined_targets is defined %}
|
||||
# Log shipment user defined target servers
|
||||
{% for target in rsyslog_client_user_defined_targets %}
|
||||
$ActionQueueFileName {{ target.name }}
|
||||
$ActionQueueSaveOnShutdown on
|
||||
$ActionQueueType LinkedList
|
||||
$ActionResumeRetryCount 250
|
||||
{% if target.template is defined %}
|
||||
{{ target.template }}
|
||||
{% endif %}
|
||||
{% if target.proto == "udp" %}
|
||||
{% set action_sting = '*.* @' %}
|
||||
{% elif target.proto == "tcp" %}
|
||||
{% set action_sting = '*.* @@' %}
|
||||
{% endif %}
|
||||
{% if target.action_options is defined %}
|
||||
{{ action_sting }}{{ target.hostname }}:{{ target.port }};{{ target.action_options }}
|
||||
{% else %}
|
||||
{{ action_sting }}{{ target.hostname }}:{{ target.port }}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
# Log files
|
||||
{% for log_file in rsyslog_client_all_log_files %}
|
||||
$InputFileName {{ log_file }}
|
||||
|
45
templates/remote-logging.j2
Normal file
45
templates/remote-logging.j2
Normal file
@ -0,0 +1,45 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
$WorkDirectory {{ rsyslog_client_spool_directory }}
|
||||
$template RFC3164fmt,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%"
|
||||
|
||||
{% if groups['rsyslog_all'] is defined and groups['rsyslog_all'] %}
|
||||
# Log shipment rsyslog target servers
|
||||
{% for server in groups['rsyslog_all'] %}
|
||||
$ActionQueueFileName {{ server }}
|
||||
$ActionQueueSaveOnShutdown on
|
||||
$ActionQueueType LinkedList
|
||||
$ActionResumeRetryCount 250
|
||||
{% if rsyslog_client_tcp_reception == true %}
|
||||
*.* @@{{ hostvars[server]['ansible_host'] }}:{{ rsyslog_client_tcp_port }};RFC3164fmt
|
||||
{% endif %}
|
||||
{% if rsyslog_client_udp_reception == true %}
|
||||
*.* @{{ hostvars[server]['ansible_host'] }}:{{ rsyslog_client_udp_port }};RFC3164fmt
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if rsyslog_client_user_defined_targets is defined %}
|
||||
# Log shipment user defined target servers
|
||||
{% for target in rsyslog_client_user_defined_targets %}
|
||||
$ActionQueueFileName {{ target.name }}
|
||||
$ActionQueueSaveOnShutdown on
|
||||
$ActionQueueType LinkedList
|
||||
$ActionResumeRetryCount 250
|
||||
{% if target.template is defined %}
|
||||
{{ target.template }}
|
||||
{% endif %}
|
||||
{% if target.proto == "udp" %}
|
||||
{% set action_sting = '*.* @' %}
|
||||
{% elif target.proto == "tcp" %}
|
||||
{% set action_sting = '*.* @@' %}
|
||||
{% endif %}
|
||||
{% if target.action_options is defined %}
|
||||
{{ action_sting }}{{ target.hostname }}:{{ target.port }};{{ target.action_options }}
|
||||
{% else %}
|
||||
{{ action_sting }}{{ target.hostname }}:{{ target.port }}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
@ -47,6 +47,10 @@
|
||||
- nocreate
|
||||
- size 1G
|
||||
post_tasks:
|
||||
- name: Open rsyslog remote logging file
|
||||
slurp:
|
||||
src: /etc/rsyslog.d/51-remote-logging.conf
|
||||
register: rsyslog_remote_logging_file
|
||||
- name: Open rsyslog client file
|
||||
slurp:
|
||||
src: /etc/rsyslog.d/99-test-rsyslog-client.conf
|
||||
@ -57,12 +61,17 @@
|
||||
register: logrotate_client_file
|
||||
- name: Read files
|
||||
set_fact:
|
||||
rsyslog_remote_logging_content: "{{ rsyslog_remote_logging_file.content | b64decode }}"
|
||||
rsyslog_client_content: "{{ rsyslog_test_client_file.content | b64decode }}"
|
||||
logrotate_client_content: "{{ logrotate_client_file.content | b64decode }}"
|
||||
- name: Check rsyslog defaults file
|
||||
stat:
|
||||
path: /etc/rsyslog.d/50-default.conf
|
||||
register: rsyslog_default_file
|
||||
- name: Check rsyslog remote logging config file
|
||||
stat:
|
||||
path: /etc/rsyslog.d/51-remote-logging.conf
|
||||
register: rsyslog_remote_logging_conf
|
||||
- name: Check rsyslog client file
|
||||
stat:
|
||||
path: /etc/rsyslog.d/99-test-rsyslog-client.conf
|
||||
@ -74,10 +83,10 @@
|
||||
- name: Check role functions
|
||||
assert:
|
||||
that:
|
||||
- "'$ActionQueueFileName test1' in rsyslog_client_content"
|
||||
- "'$ActionQueueFileName test2' in rsyslog_client_content"
|
||||
- "'$ActionQueueFileName test-splunk1' in rsyslog_client_content"
|
||||
- "'$ActionQueueFileName test-loggly1' in rsyslog_client_content"
|
||||
- "'$ActionQueueFileName test1' in rsyslog_remote_logging_content"
|
||||
- "'$ActionQueueFileName test2' in rsyslog_remote_logging_content"
|
||||
- "'$ActionQueueFileName test-splunk1' in rsyslog_remote_logging_content"
|
||||
- "'$ActionQueueFileName test-loggly1' in rsyslog_remote_logging_content"
|
||||
# check for log files that are explicitly defined in rsyslog_client_log_files
|
||||
- "'/var/log/dmesg' in logrotate_client_content"
|
||||
- "'/var/log/udev' in logrotate_client_content"
|
||||
@ -88,5 +97,6 @@
|
||||
or '/var/log/yum.log' in logrotate_client_content"
|
||||
- "'size 1G' in logrotate_client_content"
|
||||
- "rsyslog_default_file.stat.exists"
|
||||
- "rsyslog_remote_logging_conf.stat.exists"
|
||||
- "rsyslog_client_file.stat.exists"
|
||||
- "logrotate_file.stat.exists"
|
||||
|
Loading…
Reference in New Issue
Block a user