2022-01-07 09:06:18 +00:00
---
# tasks file for RHEL9-CIS
2022-02-02 11:25:03 +00:00
2022-01-07 09:06:18 +00:00
- name : Check OS version and family
2022-01-13 11:40:59 +00:00
assert :
2022-04-25 18:30:43 +01:00
that : (ansible_distribution != 'CentOS' and ansible_os_family == 'RedHat' or ansible_os_family == "Rocky") and ansible_distribution_major_version is version_compare('9', '==')
2022-02-02 11:25:03 +00:00
fail_msg : "This role can only be run against Supported OSs. {{ ansible_distribution }} {{ ansible_distribution_major_version }} is not supported."
success_msg : "This role is running against a supported OS {{ ansible_distribution }} {{ ansible_distribution_major_version }}"
2022-04-05 10:24:47 +01:00
when :
- os_check
- not system_is_ec2
2022-01-07 09:06:18 +00:00
tags :
2022-02-02 11:25:03 +00:00
- always
2022-01-07 09:06:18 +00:00
- name : Check ansible version
2022-01-13 11:40:59 +00:00
assert :
2022-02-02 11:25:03 +00:00
that : ansible_version.full is version_compare(min_ansible_version, '>=')
fail_msg : "You must use Ansible {{ min_ansible_version }} or greater"
success_msg : "This role is running a supported version of ansible {{ ansible_version.full }} >= {{ min_ansible_version }}"
2022-01-07 09:06:18 +00:00
tags :
2022-02-02 11:25:03 +00:00
- always
2022-09-07 13:35:36 +01:00
- name : "Check password set for {{ ansible_user }}"
block :
2022-09-16 11:04:19 +01:00
- name : Capture current password state of "{{ ansible_user }}"
shell : "grep {{ ansible_user }} /etc/shadow | awk -F: '{print $2}'"
changed_when : false
failed_when : false
check_mode : false
register : ansible_user_password_set
- name : "Assert that password set for {{ ansible_user }} and account not locked"
assert :
that : ansible_user_password_set.stdout | length != 0 and ansible_user_password_set.stdout != "!!"
fail_msg : "You have {{ sudo_password_rule }} enabled but the user = {{ ansible_user }} has no password set - It can break access"
success_msg : "You a password set for the {{ ansible_user }}"
vars :
sudo_password_rule : rhel9cis_rule_5_3_4
2022-09-07 13:35:36 +01:00
when :
- rhel9cis_rule_5_3_4
- not system_is_ec2
tags :
- user_passwd
2022-02-02 11:25:03 +00:00
- name : Setup rules if container
block :
- name : Discover and set container variable if required
set_fact :
system_is_container : true
- name : Load variable for container
include_vars :
file : "{{ container_vars_file }}"
2022-04-05 10:24:47 +01:00
2022-02-02 11:25:03 +00:00
- name : output if discovered is a container
debug :
msg : system has been discovered as a container
when :
- system_is_container
when :
- ansible_connection == 'docker' or
ansible_virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
tags :
- container_discovery
- always
2022-01-07 09:06:18 +00:00
- name : Check crypto-policy input
assert :
that : rhel9cis_crypto_policy in rhel9cis_allowed_crypto_policies
2022-01-13 11:40:59 +00:00
fail_msg : "Crypto policy is not a permitted version"
success_msg : "Crypto policy is a permitted version"
2022-01-07 09:06:18 +00:00
- name : Check rhel9cis_bootloader_password_hash variable has been changed
assert :
2022-04-25 16:58:11 +01:00
that : rhel9cis_bootloader_password_hash.find('grub.pbkdf2.sha512') != -1 and rhel9cis_bootloader_password_hash != 'grub.pbkdf2.sha512.changethispassword'
msg : "This role will not be able to run single user password commands as rhel9cis_bootloader_password_hash variable has not been set correctly"
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- rhel9cis_set_boot_pass
2022-04-25 16:58:11 +01:00
- rhel9cis_rule_1_4_1
2022-04-26 16:01:56 +01:00
tags :
2022-04-25 16:58:11 +01:00
- always
2022-01-07 09:06:18 +00:00
- name : "check sugroup exists if used"
block :
2022-04-05 10:24:47 +01:00
- name : "Check su group exists if defined"
shell : grep -w "{{ rhel9cis_sugroup }}" /etc/group
register : sugroup_exists
changed_when : false
failed_when : sugroup_exists.rc >= 2
tags :
- skip_ansible_lint
- name : Check sugroup if defined exists before continuing
assert :
that : sugroup_exists.rc == 0
msg : "The variable rhel9cis_sugroup is defined but does not exist please rectify"
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- rhel9cis_sugroup is defined
- rhel9cis_rule_5_7
2022-01-07 09:06:18 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rule_5.7
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : Gather the package facts
package_facts :
manager : auto
tags :
2022-04-05 10:24:47 +01:00
- always
2022-01-13 11:27:38 +00:00
2022-02-02 11:25:03 +00:00
- name : Include OS specific variables
include_vars : "{{ ansible_distribution }}.yml"
tags :
2022-04-05 10:24:47 +01:00
- always
2022-02-02 11:25:03 +00:00
2022-01-13 11:27:38 +00:00
- name : Include preliminary steps
import_tasks : prelim.yml
2022-01-07 09:06:18 +00:00
tags :
2022-04-05 10:24:47 +01:00
- prelim_tasks
- always
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run pre_remediation audit
2022-02-02 11:25:03 +00:00
include_tasks : pre_remediation_audit.yml
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- run_audit
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : Gather the package facts after prelim
2022-01-07 09:06:18 +00:00
package_facts :
manager : auto
tags :
2022-04-05 10:24:47 +01:00
- always
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : capture /etc/password variables
include_tasks : parse_etc_password.yml
2022-04-05 10:24:47 +01:00
when :
- rhel9cis_section6
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rule_5.5.2
- rule_5.6.2
- rule_6.2.9
- rule_6.2.10
- rule_6.2.11
- rhel9cis_section5
- rhel9cis_section6
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 1 tasks
import_tasks : section_1/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section1
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section1
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 2 tasks
import_tasks : section_2/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section2
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section2
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 3 tasks
import_tasks : section_3/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section3
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section3
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 4 tasks
import_tasks : section_4/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section4
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section4
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 5 tasks
import_tasks : section_5/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section5
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section5
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run Section 6 tasks
import_tasks : section_6/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section6
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section6
2022-01-07 09:06:18 +00:00
2022-06-20 17:07:39 +01:00
- name : run auditd logic
import_tasks : auditd.yml
when :
- update_audit_template
tags :
- always
2022-01-13 11:27:38 +00:00
- name : run post remediation tasks
import_tasks : post.yml
2022-01-07 09:06:18 +00:00
tags :
2022-04-05 10:24:47 +01:00
- post_tasks
- always
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : run post_remediation audit
import_tasks : post_remediation_audit.yml
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- run_audit
2022-01-07 09:06:18 +00:00
- name : Show Audit Summary
debug :
msg : "{{ audit_results.split('\n') }}"
when :
2022-04-05 10:24:47 +01:00
- run_audit
2022-07-20 17:13:33 +01:00
2022-07-25 11:28:50 +01:00
- name : If Warnings found Output count and control IDs affected
2022-07-20 17:13:33 +01:00
debug :
2023-01-13 11:05:25 +00:00
msg : "You have {{ warn_count }} Warning(s) that require investigating that are related to the following benchmark ID(s) {{ warn_control_list }}"
2022-07-25 13:26:29 +01:00
when : warn_count != 0
2022-07-20 17:13:33 +01:00
tags :
- always