Skip to content

Commit 70e354a

Browse files
committed
Update as suggested by Copilot
1 parent 4b19093 commit 70e354a

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
---
2-
- name: Install apparmor-utils
2+
- name: Install apparmor-utils (Debian/Ubuntu)
33
apt:
44
pkg: apparmor-utils
5-
state: latest
5+
state: present
66
update_cache: yes
7-
ignore_errors: true
7+
when: ansible_distribution in ['Ubuntu', 'Debian']
8+
9+
- name: Install apparmor-utils (SUSE)
10+
package:
11+
name: apparmor-utils
12+
state: present
13+
when: ansible_distribution == 'SUSE'
814

915
- name: Enable Apparmor enforce mode
1016
shell: aa-enforce /etc/apparmor.d/*
17+
changed_when: false
1118

12-
- name: Check Apparmor status
13-
shell: aa-status
14-
ignore_errors: true
19+
- name: Check Apparmor status
20+
command: aa-status
21+
failed_when: false
22+
changed_when: false
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
---
22

33
- name: Get current SELinux mode
4-
shell: getenforce || true
4+
command: getenforce
55
register: selinux_mode
6+
failed_when: false
7+
changed_when: false
68

7-
- name: Set selinux to enforcing
8-
command: setenforce enforcing
9+
- name: Set SELinux to enforcing
10+
command: setenforce Enforcing
911
changed_when: false
10-
when: selinux_mode.stdout != "Enforcing"
12+
when:
13+
- selinux_mode.rc == 0
14+
- selinux_mode.stdout not in ['Enforcing', 'Disabled']
1115

12-
- name: Ensure selinux is set permanently
13-
selinux: policy=targeted state=enforcing
14-
when: selinux_mode.stdout != "Enforcing"
16+
- name: Ensure SELinux is set permanently
17+
selinux:
18+
policy: targeted
19+
state: enforcing
20+
when:
21+
- selinux_mode.rc == 0
22+
- selinux_mode.stdout != 'Disabled'
1523

1624
- name: Check SELinux status
17-
shell: sestatus
18-
ignore_errors: true
25+
command: sestatus
26+
failed_when: false
27+
changed_when: false

0 commit comments

Comments
 (0)