userlogrotate: Ensure we use a valid group name
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2697|8|2689|7|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/465//ansiblelint">Evolix » ansible-roles » unstable #465</a>
gitea/ansible-roles/pipeline/head This commit looks good

Use user's primary group when user's name is not an existing group.
This commit is contained in:
Alexis Ben Miloud--Josselin 2024-02-01 11:06:21 +01:00
parent d67e2b122f
commit 4c9e4a30cc
2 changed files with 7 additions and 0 deletions

View file

@ -67,6 +67,7 @@ The **patch** part changes is incremented if multiple releases happen the same m
* vrrpd: variable to force update the switch script (default: false)
* webapps/nextcloud: Add Ceph volume to fstab
* webapps/nextcloud: Set home directory's mode
* userlogrotate: Use user's primary group when user's name is not an existing group
### Fixed

View file

@ -73,6 +73,9 @@ for path in ${SYSTEM_LOGS_SEARCH_PATHS[@]}; do
for file in ${log_paths}; do
user="$(user_for "${file}")"
group="$(group_for "${file}")"
if ! getent group "${user}" > /dev/null 2> /dev/null; then
group="$(id -gn "${user}")"
fi
rotate "${file}" "${group}":"${user}"
delete_old "$(dirname "${file}")"
done
@ -85,6 +88,9 @@ for path in ${APPLICATIVE_LOGS_SEARCH_PATHS[@]}; do
for file in ${log_paths}; do
user="$(user_for "${file}")"
group="$(group_for "${file}")"
if ! getent group "${user}" > /dev/null 2> /dev/null; then
group="$(id -gn "${user}")"
fi
rotate "${file}" "${group}":"${user}"
delete_old "$(dirname "${file}")"
done