Skip to content

Commit 9c1c0a0

Browse files
committed
Make Ansible in accounts_passwords_pam_faillock_dir idempotent
Change the SELinux context of /var/log/faillock only if the current context isn't correct. Resolves: https://issues.redhat.com/browse/OPENSCAP-6240
1 parent fa126a2 commit 9c1c0a0

File tree

1 file changed

+9
-1
lines changed
  • linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_dir/ansible

1 file changed

+9
-1
lines changed

linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_dir/ansible/shared.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@
1616
- python3-policycoreutils
1717
- policycoreutils-python-utils
1818

19-
- name: '{{{ rule_title }}} - Create the tally directory if it does not exist'
19+
- name: '{{{ rule_title }}} - Create the faillock directory if it does not exist'
2020
ansible.builtin.file:
2121
path: "{{ var_accounts_passwords_pam_faillock_dir }}"
2222
state: directory
2323
setype: 'faillog_t'
2424

25+
- name: '{{{ rule_title }}} - Get SELinux context for faillock directory'
26+
ansible.builtin.command: "ls -dZ {{ var_accounts_passwords_pam_faillock_dir }}"
27+
register: faillock_selinux_context
28+
changed_when: false
29+
check_mode: false
30+
2531
- name: '{{{ rule_title }}} - Ensure SELinux file context is permanently set'
2632
ansible.builtin.command:
2733
cmd: semanage fcontext -a -t faillog_t "{{ var_accounts_passwords_pam_faillock_dir }}(/.*)?"
2834
register: result_accounts_passwords_pam_faillock_dir_semanage
2935
failed_when: false
3036
changed_when:
3137
- result_accounts_passwords_pam_faillock_dir_semanage.rc == 0
38+
when: '"faillog_t" not in faillock_selinux_context.stdout'
3239

3340
- name: '{{{ rule_title }}} - Ensure SELinux file context is applied'
3441
ansible.builtin.command:
3542
cmd: restorecon -R "{{ var_accounts_passwords_pam_faillock_dir }}"
3643
register: result_accounts_passwords_pam_faillock_dir_restorecon
44+
when: '"faillog_t" not in faillock_selinux_context.stdout'

0 commit comments

Comments
 (0)