From d82e80f5af158d153f1f470f92cbeff3428bf56f Mon Sep 17 00:00:00 2001 From: fbettocchi Date: Tue, 20 May 2025 22:05:21 +0200 Subject: [PATCH] fix/logrotate_file may not exists conditional setfacl on logrotate file if it exists --- roles/splunk/tasks/configure_facl.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/roles/splunk/tasks/configure_facl.yml b/roles/splunk/tasks/configure_facl.yml index 00d4772..7455812 100644 --- a/roles/splunk/tasks/configure_facl.yml +++ b/roles/splunk/tasks/configure_facl.yml @@ -20,12 +20,23 @@ - true - false + - name: Check if logrotate_file exists + ansible.builtin.stat: + path: "{{ logrotate_file }}" + register: logrotate_stat + become: true + + - name: Set use_logrotate fact based on file existence + ansible.builtin.set_fact: + use_logrotate: "{{ logrotate_stat.stat.exists | default(false) }}" + - name: Add setfacl to logrotate script ansible.builtin.lineinfile: path: "{{ logrotate_file }}" insertbefore: 'endscript' line: ' /usr/bin/setfacl -Rm u:{{ splunk_nix_user }}:rx /var/log' become: true + when: use_logrotate - name: Check if auditd.conf is present ansible.builtin.stat: