openstack-ansible-rsyslog_c.../tasks/rsyslog_client_post_install...

105 lines
2.6 KiB
YAML

---
# Copyright 2014, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Rsyslog Setup
copy:
src: "50-default.conf"
dest: "/etc/rsyslog.d/50-default.conf"
owner: "root"
group: "root"
tags:
- rsyslog_client-install
notify:
- restart rsyslog
- name: Check if log dir exists
stat:
path: "{{ rsyslog_client_log_dir }}"
when:
- "{{ rsyslog_client_log_dir is defined }}"
register: log_dir
tags:
- rsyslog_client-install
- name: Find all log files
find:
paths: "{{ rsyslog_client_log_dir }}"
patterns: "*.log"
recurse: yes
follow: yes
file_type: file
register: log_files
changed_when: false
when:
- not log_dir | skipped
tags:
- rsyslog_client-config
- name: Union the log files
set_fact:
rsyslog_client_all_log_files: "{{ log_files.files | map(attribute='path') | list | default([]) | union(rsyslog_client_log_files) }}"
when:
- rsyslog_client_log_dir is defined
tags:
- rsyslog_client-config
- name: Set rsyslog_client_all_log_files when log_files does not exist
set_fact:
rsyslog_client_all_log_files: "{{ rsyslog_client_log_files }}"
when:
- rsyslog_client_log_dir is not defined
- name: Write rsyslog config for found log files
template:
src: "rsyslog.conf.j2"
dest: "/etc/rsyslog.conf"
owner: "root"
group: "root"
tags:
- rsyslog_client-config
notify:
- restart rsyslog
- name: Write rsyslog target file
template:
src: "99-rsyslog.conf.j2"
dest: "/etc/rsyslog.d/{{ rsyslog_client_config_name }}"
owner: "root"
group: "root"
when: (rsyslog_client_all_log_files | length) > 0
tags:
- rsyslog_client-config
notify:
- restart rsyslog
- name: Write log rotate file
template:
src: "logrotate.j2"
dest: "/etc/logrotate.d/{{ rsyslog_client_log_rotate_file }}"
owner: "root"
group: "root"
when: (rsyslog_client_all_log_files | length) > 0
tags:
- rsyslog_client-config
- name: Configure logrotate to compress logs by default
lineinfile:
dest: /etc/logrotate.conf
regexp: "^#compress"
line: "compress"
backrefs: yes
tags:
- rsyslog_client-install