Fix for lack of log rotation in Bifrost

Closes-Bug: #2033528
Change-Id: I7c2ba2b263dd84641674b60aed8971b129aa846f
This commit is contained in:
Rafal Lewandowski 2023-08-30 16:20:00 +02:00
parent 16b34f378d
commit ce445f0967
8 changed files with 186 additions and 0 deletions

View File

@ -35,6 +35,7 @@
when: not (skip_install | default(false) | bool)
- bifrost-keystone-install
- bifrost-ironic-install
- bifrost-logrotate-install
- role: bifrost-keystone-client-config
user: "{{ ansible_env.SUDO_USER | default(ansible_user_id) }}"
clouds:

View File

@ -0,0 +1,45 @@
---
# Role variables:
#
# Skip installing logrotate packages
skip_package_install: false
# Skip templating configuration file
skip_configure: false
# Skip starting logrotate service
skip_start: false
# Logrotate configuration variables:
#
# Frequency of rotation
logrotate_frequency: "weekly"
# Amount of files to keep
logrotate_file_count: 3
# To compress or to not compress
logrotate_compress: true
# Minimum size of log file
logrotate_file_minsize: "30M"
# Maximum size of log file
logrotate_file_maxsize: "100M"
# Compression delay
logrotate_delay_compression: true
# Remove old log file or truncate it
logrotate_copy_truncate: true
# Should a log file be rotated if it's empty
logrotate_not_if_empty: true
# If the file doesn't exist should error be raised
logrotate_missing_ok: true
# Log file owner
logrotate_log_user: "root"
# Log file owner group
logrotate_log_group: "root"
# Log locations
#
# Nginx default log location
nginx_log_dir: "/var/log/nginx"
# Keystone default log location
keystone_log_dir: "{{ nginx_log_dir }}/nginx/keystone"
logrotate_components:
- "{{ nginx_log_dir }}"
- "{{ keystone_log_dir }}"

View File

@ -0,0 +1,18 @@
# 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: "Template logrotate config"
template:
src: "logrotate.conf.j2"
dest: "/etc/logrotate.conf"
mode: "0600"

View File

@ -0,0 +1,17 @@
# 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: "Install logrotate"
package:
name: logrotate
state: present

View File

@ -0,0 +1,24 @@
# 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: "Install logrotate"
include_tasks: install.yml
when: not skip_package_install | bool
- name: "Configure logrotate"
include_tasks: configure.yml
when: not skip_configure | bool
- name: "Start logrotate"
include_tasks: start.yml
when: not skip_start | bool

View File

@ -0,0 +1,22 @@
# 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: "Reload systemd configuration"
systemd:
daemon_reload: yes
- name: "Ensure logrotate service is started"
service:
name: logrotate
state: started
enabled: true

View File

@ -0,0 +1,53 @@
{{ logrotate_frequency }}
rotate {{ logrotate_file_count }}
{% if logrotate_copy_truncate %}
copytruncate
{% else %}
create
{% endif %}
{% if logrotate_compress %}
compress
{% else %}
nocompress
{% endif %}
{% if logrotate_delay_compression %}
delaycompress
{% else %}
nodelaycompress
{% endif %}
{% if logrotate_not_if_empty %}
notifempty
{% else %}
ifempty
{% endif %}
{% if logrotate_missing_ok %}
missingok
{% else %}
nomissingok
{% endif %}
minsize {{ logrotate_file_minsize }}
maxsize {{ logrotate_file_maxsize }}
{% for component in logrotate_components %}
"{{ component }}/*.log"
{
}
{% endfor %}
{% if ironic_log_dir is defined %}
"{{ ironic_log_dir }}/*.log"
{
}
{% endif %}
{% if inspector_log_dir is defined %}
"{{ inspector_log_dir }}/*.log"
{
}
{% endif %}

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes issue of lack of log rotation for Ironic logs by
adding a role which installs and configures the logrotate
service.