diff --git a/playbooks/install.yaml b/playbooks/install.yaml index dcb0032d5..ff6ebc48e 100644 --- a/playbooks/install.yaml +++ b/playbooks/install.yaml @@ -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: diff --git a/playbooks/roles/bifrost-logrotate-install/defaults/main.yml b/playbooks/roles/bifrost-logrotate-install/defaults/main.yml new file mode 100644 index 000000000..ab15b6347 --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/defaults/main.yml @@ -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 }}" diff --git a/playbooks/roles/bifrost-logrotate-install/tasks/configure.yml b/playbooks/roles/bifrost-logrotate-install/tasks/configure.yml new file mode 100644 index 000000000..631896a62 --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/tasks/configure.yml @@ -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" diff --git a/playbooks/roles/bifrost-logrotate-install/tasks/install.yml b/playbooks/roles/bifrost-logrotate-install/tasks/install.yml new file mode 100644 index 000000000..5ffe652ed --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/tasks/install.yml @@ -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 diff --git a/playbooks/roles/bifrost-logrotate-install/tasks/main.yml b/playbooks/roles/bifrost-logrotate-install/tasks/main.yml new file mode 100644 index 000000000..b5232fdc6 --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/tasks/main.yml @@ -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 diff --git a/playbooks/roles/bifrost-logrotate-install/tasks/start.yml b/playbooks/roles/bifrost-logrotate-install/tasks/start.yml new file mode 100644 index 000000000..ed770dfdc --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/tasks/start.yml @@ -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 diff --git a/playbooks/roles/bifrost-logrotate-install/templates/logrotate.conf.j2 b/playbooks/roles/bifrost-logrotate-install/templates/logrotate.conf.j2 new file mode 100644 index 000000000..100877509 --- /dev/null +++ b/playbooks/roles/bifrost-logrotate-install/templates/logrotate.conf.j2 @@ -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 %} \ No newline at end of file diff --git a/releasenotes/notes/fix_logrotate-bb2c38c42d9e43eb.yaml b/releasenotes/notes/fix_logrotate-bb2c38c42d9e43eb.yaml new file mode 100644 index 000000000..80695c8e4 --- /dev/null +++ b/releasenotes/notes/fix_logrotate-bb2c38c42d9e43eb.yaml @@ -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.