Fix linter errors

Work around the mutually incompatible W503 and W504.

Change-Id: I45d0ca8a911d9cf1af2df52a1cf911db817b13b3
This commit is contained in:
Jonathan Rosser 2021-01-19 15:34:52 +00:00 committed by Dmitriy Rabotyagov
parent 4e44a54b95
commit c6703cd5e5
9 changed files with 32 additions and 18 deletions

4
.ansible-lint Normal file
View File

@ -0,0 +1,4 @@
---
skip_list:
- '106'

View File

@ -109,8 +109,8 @@ def main():
# Get the users that match our criteria. # Get the users that match our criteria.
user_list = [x for x in all_users user_list = [x for x in all_users
if (x['uid'] >= module.params['min_uid'] and if (x['uid'] >= module.params['min_uid']
x['uid'] <= module.params['max_uid'])] and x['uid'] <= module.params['max_uid'])] # noqa: W503
# Return the user data to the Ansible task. # Return the user data to the Ansible task.
module.exit_json( module.exit_json(
@ -118,5 +118,6 @@ def main():
users=user_list users=user_list
) )
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -4,22 +4,25 @@ galaxy_info:
description: Security hardening role for OpenStack-Ansible description: Security hardening role for OpenStack-Ansible
company: OpenStack company: OpenStack
license: Apache license: Apache
min_ansible_version: 2.3 min_ansible_version: 2.10
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- jessie - jessie
- buster
- name: Fedora - name: Fedora
versions: versions:
- 25 - 25
- name: EL - name: EL
versions: versions:
- 7 - 7
- 8
- name: Ubuntu - name: Ubuntu
versions: versions:
- trusty - trusty
- xenial - xenial
- bionic - bionic
- focal
- name: opensuse - name: opensuse
versions: versions:
- 42.1 - 42.1

View File

@ -83,7 +83,7 @@
# may be attached to a Kerberos realm and they may not have shadow data on the # may be attached to a Kerberos realm and they may not have shadow data on the
# system. See bug 1659232 for more details. # system. See bug 1659232 for more details.
- name: Set minimum password lifetime limit to 24 hours for interactive accounts - name: Set minimum password lifetime limit to 24 hours for interactive accounts
shell: "chage -m 1 {{ item.name }}" command: "chage -m 1 {{ item.name }}"
when: when:
- item.shadow is mapping - item.shadow is mapping
- item.shadow.min_days != 1 - item.shadow.min_days != 1
@ -99,7 +99,7 @@
# may be attached to a Kerberos realm and they may not have shadow data on the # may be attached to a Kerberos realm and they may not have shadow data on the
# system. See bug 1659232 for more details. # system. See bug 1659232 for more details.
- name: Set maximum password lifetime limit to 60 days for interactive accounts - name: Set maximum password lifetime limit to 60 days for interactive accounts
shell: "chage -M 60 {{ item.name }}" command: "chage -M 60 {{ item.name }}"
when: when:
- item.shadow is mapping - item.shadow is mapping
- item.shadow.max_days > 60 - item.shadow.max_days > 60
@ -144,7 +144,7 @@
line: "{{ item.parameter }} {{ item.value }}" line: "{{ item.parameter }} {{ item.value }}"
state: present state: present
when: when:
- item.value != '' - item.value is truthy(convert_bool=True)
- item.ansible_os_family == 'all' or item.ansible_os_family == ansible_os_family - item.ansible_os_family == 'all' or item.ansible_os_family == ansible_os_family
with_items: "{{ shadow_utils_rhel7 }}" with_items: "{{ shadow_utils_rhel7 }}"
tags: tags:
@ -210,7 +210,7 @@
stat: stat:
path: "{{ item['dir'] }}" path: "{{ item['dir'] }}"
when: when:
- item['dir'] != '' - item['dir'] | length > 0
with_items: "{{ user_list.users }}" with_items: "{{ user_list.users }}"
register: home_directory_checks register: home_directory_checks
tags: tags:

View File

@ -177,7 +177,8 @@
- name: Set a GRUB 2 password for single-user/maintenance modes - name: Set a GRUB 2 password for single-user/maintenance modes
block: block:
- blockinfile: - name: Define password options for grub
blockinfile:
path: "{{ grub_custom_file }}" path: "{{ grub_custom_file }}"
insertbefore: EOF insertbefore: EOF
marker: "# {mark} MANAGED BY ANSIBLE-HARDENING" marker: "# {mark} MANAGED BY ANSIBLE-HARDENING"
@ -187,7 +188,8 @@
state: present state: present
notify: notify:
- update grub config - update grub config
- lineinfile: - name: Set CLASS for grub file
lineinfile:
path: "{{ grub_linux_file }}" path: "{{ grub_linux_file }}"
regexp: '^CLASS=.*' regexp: '^CLASS=.*'
line: 'CLASS="--class gnu-linux --class gnu --class os --unrestricted"' line: 'CLASS="--class gnu-linux --class gnu --class os --unrestricted"'
@ -246,8 +248,8 @@
failed_when: False failed_when: False
changed_when: False changed_when: False
register: job_result register: job_result
until: job_result.finished | bool until: job_result.finished
retries: 30 retries: 60
when: when:
- shosts_find is not skipped - shosts_find is not skipped
tags: tags:

View File

@ -49,7 +49,7 @@
- C-00001 - C-00001
- name: Check kdump service - name: Check kdump service
command: systemctl status kdump command: systemctl status kdump # noqa 303
register: kdump_service_check register: kdump_service_check
failed_when: kdump_service_check.rc not in [0,3,4] failed_when: kdump_service_check.rc not in [0,3,4]
changed_when: False changed_when: False

View File

@ -21,6 +21,7 @@
failed_when: false failed_when: false
when: when:
- ansible_pkg_mgr in ['apt', 'zypper'] - ansible_pkg_mgr in ['apt', 'zypper']
- security_rhel7_enable_linux_security_module | bool
tags: tags:
- high - high
- V-71989 - V-71989
@ -31,13 +32,14 @@
# started apparmor each time. This breaks idempotency and we check # started apparmor each time. This breaks idempotency and we check
# systemd's status directly as an alternative. # systemd's status directly as an alternative.
- name: Check if apparmor is running - name: Check if apparmor is running
command: "systemctl status apparmor" command: "systemctl status apparmor" # noqa 303
register: systemctl_apparmor_status register: systemctl_apparmor_status
check_mode: no check_mode: no
changed_when: false changed_when: false
failed_when: false failed_when: false
when: when:
- ansible_pkg_mgr in ['apt', 'zypper'] - ansible_pkg_mgr in ['apt', 'zypper']
- security_rhel7_enable_linux_security_module | bool
tags: tags:
- high - high
- V-71989 - V-71989
@ -49,6 +51,7 @@
when: when:
- ansible_pkg_mgr in ['apt', 'zypper'] - ansible_pkg_mgr in ['apt', 'zypper']
- security_rhel7_enable_linux_security_module | bool - security_rhel7_enable_linux_security_module | bool
- not check_mode
tags: tags:
- high - high
- V-71989 - V-71989

View File

@ -14,9 +14,10 @@
# limitations under the License. # limitations under the License.
- name: Create temporary directory to hold any temporary files - name: Create temporary directory to hold any temporary files
command: "mktemp -d" tempfile:
state: directory
suffix: hardening
register: mktemp_result register: mktemp_result
changed_when: False
when: when:
- not check_mode | bool - not check_mode | bool
tags: tags:
@ -24,7 +25,7 @@
- name: Set a fact for the temporary directory - name: Set a fact for the temporary directory
set_fact: set_fact:
temp_dir: "{{ mktemp_result.stdout }}" temp_dir: "{{ mktemp_result.path }}"
changed_when: False changed_when: False
when: when:
- not check_mode | bool - not check_mode | bool

View File

@ -14,7 +14,7 @@
# limitations under the License. # limitations under the License.
- name: Check autofs service - name: Check autofs service
command: systemctl status autofs command: systemctl status autofs # noqa 303
register: autofs_check register: autofs_check
failed_when: autofs_check.rc not in [0,3,4] failed_when: autofs_check.rc not in [0,3,4]
changed_when: False changed_when: False
@ -289,7 +289,7 @@
# Returns 0 if installed, 3 if not installed # Returns 0 if installed, 3 if not installed
- name: Check firewalld status - name: Check firewalld status
command: systemctl status firewalld command: systemctl status firewalld # noqa 303
register: firewalld_status_check register: firewalld_status_check
failed_when: firewalld_status_check.rc not in [0,3,4] failed_when: firewalld_status_check.rc not in [0,3,4]
changed_when: False changed_when: False