Skip to content

Commit 8c5d2d0

Browse files
committed
NetworkManager package and PAM stat files fixes
- Fixed NetworkManager package issue for ubuntu2204 and ubuntu2404. - ubuntu didn't need Network manager so this created a custom wirless_disable_interfaces for ubuntu for ansible, similar to how it was done in bash. - Resolved issue where using the same register variable outside and inside the block were causing failures. - Add rule_title to all tasks for wireless_disable_interfactes ansible. Signed-off-by: Shane Dell <[email protected]>
1 parent fe723c2 commit 8c5d2d0

File tree

7 files changed

+100
-11
lines changed

7 files changed

+100
-11
lines changed

Dockerfiles/test_suite-ubi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ RUN true \
2121
&& chmod og-rw /root/.ssh "$AUTH_KEYS" \
2222
&& sed -i '/session\s\+required\s\+pam_loginuid.so/d' /etc/pam.d/sshd \
2323
&& true
24-

linux_os/guide/system/accounts/accounts-pam/set_password_hashing_algorithm/set_password_hashing_algorithm_passwordauth/ansible/shared.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- name: '{{{ rule_title }}} - Check if {{{ pam_file }}} File is Present'
1313
ansible.builtin.stat:
1414
path: {{{ pam_file }}}
15-
register: result_pam_file_present
15+
register: result_pam_password_auth_file_present
1616

1717
- name: '{{{ rule_title }}} - Check The Proper Remediation For The System'
1818
block:
@@ -46,4 +46,4 @@
4646
- result_authselect_present.stat.exists
4747
- result_pam_hashing_options_removal is changed
4848
when:
49-
- result_pam_file_present.stat.exists
49+
- result_pam_password_auth_file_present.stat.exists

linux_os/guide/system/accounts/accounts-pam/set_password_hashing_algorithm/set_password_hashing_algorithm_systemauth/ansible/shared.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- name: '{{{ rule_title }}} - Check if {{{ pam_file }}} File is Present'
1919
ansible.builtin.stat:
2020
path: {{{ pam_file }}}
21-
register: result_pam_file_present
21+
register: result_pam_auth_file_present
2222

2323
- name: '{{{ rule_title }}} - Check The Proper Remediation For The System'
2424
block:
@@ -52,4 +52,4 @@
5252
- result_authselect_present.stat.exists
5353
- result_pam_hashing_options_removal is changed
5454
when:
55-
- result_pam_file_present.stat.exists
55+
- result_pam_auth_file_present.stat.exists

linux_os/guide/system/network/network-wireless/wireless_software/wireless_disable_interfaces/ansible/shared.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
# complexity = low
55
# disruption = medium
66

7-
- name: Service facts
7+
- name: "{{{ rule_title }}} - Service facts"
88
ansible.builtin.service_facts:
99

1010
{{% if product in ["sle12", "sle15", "slmicro5"] %}}
1111

12-
- name: Wicked Deactivate Wireless Network Interfaces
12+
- name: "{{{ rule_title }}} - Wicked Deactivate Wireless Network Interfaces"
1313
ansible.builtin.command: wicked ifdown {{ item }}
1414
loop: '{{ ansible_facts.interfaces }}'
1515
when:
1616
- ansible_facts.services['wickedd.service'].state == 'running'
1717
- 'item.startswith("wl")'
1818

19-
- name: Wicked Disable Wireless Network Interfaces
19+
- name: "{{{ rule_title }}} - Wicked Disable Wireless Network Interfaces"
2020
ansible.builtin.lineinfile:
2121
path: /etc/sysconfig/network/ifcfg-{{ item }}
2222
regexp: '^STARTMODE='
@@ -27,7 +27,7 @@
2727
- 'item.startswith("wl")'
2828
{{%- else %}}
2929

30-
- name: Ensure NetworkManager is installed
30+
- name: "{{{ rule_title }}} - Ensure NetworkManager is installed"
3131
ansible.builtin.package:
3232
name: "{{ item }}"
3333
state: present
@@ -36,7 +36,7 @@
3636

3737
{{%- endif %}}
3838

39-
- name: NetworkManager Deactivate Wireless Network Interfaces
39+
- name: "{{{ rule_title }}} - NetworkManager Deactivate Wireless Network Interfaces"
4040
ansible.builtin.command: nmcli radio wifi off
4141
when:
4242
- "'NetworkManager' in ansible_facts.packages"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# platform = multi_platform_ubuntu
2+
# reboot = false
3+
# strategy = unknown
4+
# complexity = low
5+
# disruption = medium
6+
7+
- name: "{{{ rule_title }}} - Find wireless marker directories"
8+
ansible.builtin.find:
9+
paths: "/sys/class/net"
10+
file_type: directory
11+
patterns: "wireless"
12+
recurse: yes
13+
register: wireless_paths
14+
15+
- name: "{{{ rule_title }}} - Extract interface names from directory paths"
16+
ansible.builtin.set_fact:
17+
wireless_interfaces: >-
18+
{{ wireless_paths.files | map('dirname') | map('basename') | list }}
19+
20+
- name: "{{{ rule_title }}} - Bring wireless interfaces down"
21+
ansible.builtin.command:
22+
cmd: "ip link set dev {{ item }} down"
23+
with_items: "{{ wireless_interfaces }}"
24+
when: wireless_interfaces | length > 0
25+
26+
- name: "{{{ rule_title }}} - Get driver name for each interface"
27+
ansible.builtin.command:
28+
cmd: "basename $(readlink -f /sys/class/net/{{ item }}/device/driver)"
29+
register: wireless_drivers
30+
with_items: "{{ wireless_interfaces }}"
31+
changed_when: false
32+
check_mode: false
33+
when: wireless_interfaces | length > 0
34+
35+
- name: "{{{ rule_title }}} - Create disable wireless driver modprobe config"
36+
ansible.builtin.blockinfile:
37+
path: /etc/modprobe.d/disable_wireless.conf
38+
create: yes
39+
block: |
40+
{% for r in wireless_drivers.results %}
41+
install {{ r.stdout }} /bin/false
42+
{% endfor %}
43+
when: wireless_interfaces | length > 0
44+
45+
- name: "{{{ rule_title }}} - Unload wireless kernel modules"
46+
ansible.builtin.command:
47+
cmd: "modprobe -r {{ item.stdout }}"
48+
with_items: "{{ wireless_drivers.results }}"
49+
when: wireless_interfaces | length > 0

shared/applicability/package.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ args:
6969
pkgname: snmp
7070
{{% endif %}}
7171
networkmanager:
72+
{{% if product in ["ubuntu2204", "ubuntu2404"] %}}
73+
pkgname: network-manager
74+
{{% else %}}
7275
pkgname: NetworkManager
76+
{{% endif %}}
7377
nftables:
7478
pkgname: nftables
7579
nss-pam-ldapd:

shared/macros/10-ansible.jinja

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,13 @@ Part of the grub2_bootloader_argument_absent template.
18361836
- name: '{{{ rule_title }}} - Check if {{{ pam_file }}} file is present'
18371837
ansible.builtin.stat:
18381838
path: "{{{ pam_file }}}"
1839+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
1840+
register: result_pam_password_auth_file_present
1841+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
1842+
register: result_pam_auth_file_present
1843+
{{%- else %}}
18391844
register: result_pam_file_present
1845+
{{%- endif %}}
18401846

18411847
- name: '{{{ rule_title }}} - Ensure the "{{{ option }}}" option from "{{{ module }}}" is not present in {{{ pam_file }}}'
18421848
ansible.builtin.replace:
@@ -1848,7 +1854,14 @@ Part of the grub2_bootloader_argument_absent template.
18481854
{{%- endif %}}
18491855
replace: '\1\2'
18501856
register: result_pam_option_removal
1851-
when: result_pam_file_present.stat.exists
1857+
when:
1858+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
1859+
- result_pam_password_auth_file_present.stat.exists
1860+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
1861+
- result_pam_auth_file_present.stat.exists
1862+
{{%- else %}}
1863+
- result_pam_file_present.stat.exists
1864+
{{%- endif %}}
18521865
{{%- endmacro -%}}
18531866

18541867

@@ -2016,7 +2029,13 @@ Part of the grub2_bootloader_argument_absent template.
20162029
- name: '{{{ rule_title }}} - Check if {{{ pam_file }}} file is present'
20172030
ansible.builtin.stat:
20182031
path: {{{ pam_file }}}
2032+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
2033+
register: result_pam_password_auth_file_present
2034+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
2035+
register: result_pam_auth_file_present
2036+
{{%- else %}}
20192037
register: result_pam_file_present
2038+
{{%- endif %}}
20202039

20212040
- name: '{{{ rule_title }}} - Check the proper remediation for the system'
20222041
block:
@@ -2035,7 +2054,13 @@ Part of the grub2_bootloader_argument_absent template.
20352054
(result_pam_{{{ rule_id }}}_add is defined and result_pam_{{{ rule_id }}}_add.changed)
20362055
or (result_pam_{{{ rule_id }}}_edit is defined and result_pam_{{{ rule_id }}}_edit.changed)
20372056
when:
2057+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
2058+
- result_pam_password_auth_file_present.stat.exists
2059+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
2060+
- result_pam_auth_file_present.stat.exists
2061+
{{%- else %}}
20382062
- result_pam_file_present.stat.exists
2063+
{{%- endif %}}
20392064
{{%- endmacro -%}}
20402065

20412066

@@ -2060,7 +2085,13 @@ Part of the grub2_bootloader_argument_absent template.
20602085
- name: '{{{ rule_title }}} - Check if {{{ pam_file }}} file is present'
20612086
ansible.builtin.stat:
20622087
path: {{{ pam_file }}}
2088+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
2089+
register: result_pam_password_auth_file_present
2090+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
2091+
register: result_pam_auth_file_present
2092+
{{%- else %}}
20632093
register: result_pam_file_present
2094+
{{%- endif %}}
20642095

20652096
- name: '{{{ rule_title }}} - Check the proper remediation for the system'
20662097
block:
@@ -2073,7 +2104,13 @@ Part of the grub2_bootloader_argument_absent template.
20732104
- result_authselect_present.stat.exists
20742105
- result_pam_option_removal is changed
20752106
when:
2107+
{{%- if pam_file == "/etc/pam.d/password-auth" %}}
2108+
- result_pam_password_auth_file_present.stat.exists
2109+
{{%- elif pam_file in ["/etc/pam.d/common-password", "/etc/pam.d/system-auth"] %}}
2110+
- result_pam_auth_file_present.stat.exists
2111+
{{%- else %}}
20762112
- result_pam_file_present.stat.exists
2113+
{{%- endif %}}
20772114
{{%- endmacro -%}}
20782115

20792116

0 commit comments

Comments
 (0)