Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preflight OS, CPU, RAM, Swap, and Filesystem checks #326

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

Kushal-deb
Copy link

@Kushal-deb Kushal-deb commented Feb 3, 2025

  • Implemented OS, NIC and Other preflight checks to validate system requirements before Ceph cluster creation.

    • Checks include:
      • OS version (RHEL 9+ required)
      • SELinux enforcing mode
      • Firewalld installation and status
      • Required package availability (rpcbind, podman, firewalld)
      • Podman version check (>= 3.3)
      • RHEL software profile validation
      • Tuned profile check
      • CPU, RAM, Swap, and Filesystem (part of other checks)
      • Check whether jumbo frames are enabled
      • Is it configured with DHCP or static IP
      • Is the bandwidth sufficient
      • Collect and output current NIC options set (e.g. Bonding, not bridged or virtual)
      • Check and report network latency (ping) with all hosts provided in the inventory file
      • Separate NICs for front-end and back-end networks

Enhancements:

❯ ansible-playbook -i ~/ansible-inventory/inventory.ini cephadm-preflight.yml                                                                                                                                                              ─╯

PLAY [insecure_registries] *******************************************************************************************************************************************************************************************************************

TASK [fail if insecure_registry is undefined] ************************************************************************************************************************************************************************************************
skipping: [rhel-ceph-admin]

PLAY [preflight] *****************************************************************************************************************************************************************************************************************************

TASK [fail when ceph_origin is custom with no repository defined] ****************************************************************************************************************************************************************************
skipping: [rhel-ceph-admin]

TASK [fail if baseurl is not defined for ceph_custom_repositories] ***************************************************************************************************************************************************************************
skipping: [rhel-ceph-admin]

PLAY [all] ***********************************************************************************************************************************************************************************************************************************

TASK [Initialize preflight results list] *****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Check if OS is RHEL 9+] ****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store OS check result] *****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Ensure SELinux is set to Enforcing mode] ***********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Retrieve SELinux status from ansible_facts] ********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Determine SELinux Check Result] ********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Determine SELinux Failure Reason] ******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store SELinux check result] ************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Ensure required packages are installed] ************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Determine Package Installation Check Result] *******************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Determine Package Installation Failure Reason] *****************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Package Installation Result] *****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Ensure firewalld is enabled and running] ***********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Determine Firewalld Check Status] ******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Firewalld check result] **********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Collect installed package facts] *******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Check if Podman is installed] **********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Extract Podman version] ****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define Podman Check Variables] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Podman Installation Check] *******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Ensure Podman is installed if missing (Fixable)] ***************************************************************************************************************************************************************************************
skipping: [rhel-ceph-admin]

TASK [Validate RHEL software profile] ********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define RHEL Profile Check Result] ******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define RHEL Profile Check Reason] ******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store RHEL Profile check] **************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get current tuned profile] *************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define Tuned Profile Check Result] *****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define Tuned Profile Check Reason] *****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Tuned Profile Check] *************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Check if CPU supports x86-64-v2 (AVX2 required for RHEL 9)] ****************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define CPU x86-64-v2 Check Variables] **************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store CPU Instruction Set Check Result] ************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get available CPU cores using Ansible facts] *******************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define CPU Core Check Variables] *******************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store CPU Core Check] ******************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get total RAM using Ansible facts] *****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define RAM Check Variables] ************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store RAM Check Result] ****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get total swap space using Ansible facts] **********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Calculate required swap space] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Set Swap Space Check Variables] ********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Swap Space Check] ****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Check if /var is a separate partition] *************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Set /var Partition Check Variables] ****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store /var Partition Check] ************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get root filesystem size] **************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Set Root Filesystem Check Variables] ***************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Root Filesystem Check] ***********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get active network interfaces] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Extract MTU for jumbo frames Check] ****************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define jumbo frames Check Variables] ***************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store jumbo frames Check] **************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Extract NIC IP Configuration] **********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define NIC Configuration Check Variables] **********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store NIC Configuration Check] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Extract NIC Bandwidth] *****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define NIC Bandwidth Check Variables] **************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store NIC Bandwidth Check] *************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Get NIC Configuration Details] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define NIC Configuration Check Variables] **********************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store NIC Configuration Check] *********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Ping all hosts in inventory] ***********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin] => (item=rhel-ceph-admin)

TASK [Define Network Latency Check Variables] ************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Network Latency Check] ***********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Identify Front-End NIC] ****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Identify Back-End NIC] *****************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Define Front-End & Back-End NIC Separation Check Variables] ****************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Store Front-End & Back-End NIC Separation Check] ***************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Generate Preflight Check Report] *******************************************************************************************************************************************************************************************************
changed: [rhel-ceph-admin -> localhost]

TASK [Display Preflight Check Report] ********************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin]

TASK [Show Report Summary] *******************************************************************************************************************************************************************************************************************
ok: [rhel-ceph-admin] => 
  msg:
  - Preflight Check Report
  - ''
  - ==================================================
  - '    **System Checks**'
  - '--------------------------------------------------'
  - '- **OS Version**: ✅ Passed  -   **Reason:** N/A'
  - '- **SELinux**: ✅ Passed  -   **Reason:** N/A'
  - '- **Firewalld Running**: ✅ Passed  -   **Reason:** N/A'
  - '- **Podman Installed**: ✅ Passed  -   **Reason:** Podman version is 5.2.2'
  - '- **RHEL Profile**: ❌ Failed  -   **Reason:** Incorrect RHEL software profile. Expected: Server with File and Storage Server.'
  - '- **Tuned Profile**: ❌ Failed  -   **Reason:** Incorrect tuned profile. Expected: throughput-performance'
  - '- **CPU x86-64-v2**: ✅ Passed  -   **Reason:** N/A'
  - '- **CPU Cores >= 4**: ✅ Passed  -   **Reason:** N/A'
  - '- **Minimum RAM (8GB)**: ❌ Failed  -   **Reason:** System has only 7684 MB RAM, required: 8192MB'
  - '- **Swap Space (1.5x RAM)**: ❌ Failed  -   **Reason:** System has only 5119 MB Swap, required: 11526 MB'
  - '- **/var is a separate partition**: ❌ Failed  -   **Reason:** /var is not a separate partition'
  - '- **Root Filesystem >= 100GB**: ❌ Failed  -   **Reason:** Root FS is only 43GB, required: 100GB'
  - '- **Jumbo Frames Enabled**: ❌ Failed  -   **Reason:** MTU is 1500, recommended > 1500'
  - '- **NIC Static IP Configuration**: ❌ Failed  -   **Reason:** NIC is using DHCP, static IP is recommended'
  - '- **NIC Bandwidth (10GbE Recommended)**: ❌ Failed  -   **Reason:** NIC speed is -1 Mbps, recommended is 10GbE'
  - '- **NIC Configuration**: ❌ Failed  -   **Reason:** NIC options: lo, ens3'
  - '- **Network Latency**: ❌ Failed  -   **Reason:** Latency results: [''pong'']'
  - '- **Separate NICs for Frontend & Backend Networks**: ❌ Failed  -   **Reason:** Using same NIC for both front-end and back-end networks. Customers with large deployments should separate traffic for performance optimization.'
  - ''
  - ==================================================
  - '     **Summary**'
  - '--------------------------------------------------'
  - '❌ **Critical Failures Detected**: '
  - '   - RHEL Profile, Tuned Profile, Minimum RAM, Swap Space, /var Partition, Root Filesystem, Jumbo Frames, NIC Configuration, NIC Bandwidth, NIC Separation'
  - '   -   **Action Required**: Please fix the above issues before proceeding.'

TASK [Final Check - Fail if any critical checks failed] **************************************************************************************************************************************************************************************
fatal: [rhel-ceph-admin]: FAILED! => changed=false 
  msg: 'Preflight checks failed for the following: RHEL Profile, Tuned Profile, Minimum RAM, Swap Space, /var Partition, Root Filesystem, Jumbo Frames, NIC Configuration, NIC Bandwidth, NIC Separation. Please resolve these issues before proceeding.'

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
rhel-ceph-admin            : ok=70   changed=1    unreachable=0    failed=1    skipped=4    rescued=0    ignored=0   

cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@guits guits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, avoid as much as possible using ignore_errors: true

cephadm-preflight.yml Outdated Show resolved Hide resolved
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from 5d002a4 to 280a9cf Compare February 5, 2025 07:53
@Kushal-deb Kushal-deb requested a review from guits February 5, 2025 07:57
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
cephadm-preflight.yml Outdated Show resolved Hide resolved
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from 280a9cf to 2a6cb0f Compare February 5, 2025 14:30
@Kushal-deb Kushal-deb requested a review from guits February 5, 2025 14:41
cephadm-preflight.yml Outdated Show resolved Hide resolved
@Kushal-deb Kushal-deb changed the title Add preflight OS checks Add preflight OS and other checks Feb 6, 2025
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from 2a6cb0f to e837ef9 Compare February 6, 2025 11:38
@Kushal-deb Kushal-deb requested a review from guits February 6, 2025 11:39
@Kushal-deb Kushal-deb changed the title Add preflight OS and other checks Add preflight OS , CPU, RAM, Swap, and Filesystem checks Feb 6, 2025
@Kushal-deb Kushal-deb changed the title Add preflight OS , CPU, RAM, Swap, and Filesystem checks Add preflight OS, CPU, RAM, Swap, and Filesystem checks Feb 6, 2025
@Kushal-deb Kushal-deb closed this Feb 6, 2025
@Kushal-deb Kushal-deb deleted the implement_os_preflight_checks branch February 6, 2025 11:43
@Kushal-deb Kushal-deb restored the implement_os_preflight_checks branch February 6, 2025 11:43
@Kushal-deb Kushal-deb reopened this Feb 6, 2025
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from e837ef9 to 6e47331 Compare February 6, 2025 17:19
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from 6e47331 to 9546e44 Compare February 11, 2025 08:25
@Kushal-deb Kushal-deb requested a review from guits February 11, 2025 09:49
preflight_checks.yml Outdated Show resolved Hide resolved
preflight_checks.yml Outdated Show resolved Hide resolved
preflight_checks.yml Outdated Show resolved Hide resolved
preflight_checks.yml Outdated Show resolved Hide resolved
- Implemented OS preflight checks to validate system requirements before Ceph cluster creation.
- Checks include:
  - OS version (RHEL 9+ required)
  - SELinux enforcing mode
  - Firewalld installation and status
  - Required package availability (rpcbind, podman, firewalld)
  - Podman version check (>= 3.3)
  - RHEL software profile validation
  - Tuned profile check
  - CPU, RAM, Swap, and Filesystem (part of other checks)
  - Check whether jumbo frames are enabled
  - Is it configured with DHCP or static IP
  - Is the bandwidth sufficient
  - Collect and output current NIC options set (e.g. Bonding, not bridged or virtual)
  - Check and report network latency (ping) with all hosts provided in the inventory file
  - Separate NICs for front-end and back-end networks
@Kushal-deb Kushal-deb force-pushed the implement_os_preflight_checks branch from 9546e44 to 39a250e Compare February 11, 2025 15:06
@Kushal-deb Kushal-deb requested a review from guits February 11, 2025 15:10
@asm0deuz
Copy link
Collaborator

jenkins test el9-functional

2 similar comments
@Kushal-deb
Copy link
Author

jenkins test el9-functional

@asm0deuz
Copy link
Collaborator

jenkins test el9-functional

@@ -0,0 +1,314 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, make it an actual playbook:

Suggested change
---
---
- hosts: all
become: true
gather_facts: true
tasks:
- name: Initialize preflight results list
set_fact:
preflight_results: []
preflight_failures: []

Comment on lines +48 to +66
- name: Ensure required packages are installed
package:
name: "{{ infra_pkgs }}"
state: present
register: package_install
failed_when: false

- name: Determine Package Installation Check Result
set_fact:
package_check: "{{ 'PASS' if not package_install.failed else 'FAIL' }}"

- name: Determine Package Installation Failure Reason
set_fact:
package_reason: "{{ 'Some required packages failed to install' if package_check == 'FAIL' else 'N/A' }}"

- name: Store Package Installation Result
set_fact:
preflight_results: "{{ preflight_results + [{'Check': 'Required Packages Installed', 'Result': package_check, 'Reason': package_reason}] }}"
preflight_failures: "{{ preflight_failures + ['Required Packages'] if package_check == 'FAIL' else preflight_failures }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cephadm-preflight playbook already handles package installation.

Suggested change
- name: Ensure required packages are installed
package:
name: "{{ infra_pkgs }}"
state: present
register: package_install
failed_when: false
- name: Determine Package Installation Check Result
set_fact:
package_check: "{{ 'PASS' if not package_install.failed else 'FAIL' }}"
- name: Determine Package Installation Failure Reason
set_fact:
package_reason: "{{ 'Some required packages failed to install' if package_check == 'FAIL' else 'N/A' }}"
- name: Store Package Installation Result
set_fact:
preflight_results: "{{ preflight_results + [{'Check': 'Required Packages Installed', 'Result': package_check, 'Reason': package_reason}] }}"
preflight_failures: "{{ preflight_failures + ['Required Packages'] if package_check == 'FAIL' else preflight_failures }}"

Comment on lines +68 to +74
- name: Ensure firewalld is enabled and running
systemd:
name: firewalld
state: started
enabled: true
register: firewall_status
failed_when: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just move this task to cephadm-preflight.yml

Suggested change
- name: Ensure firewalld is enabled and running
systemd:
name: firewalld
state: started
enabled: true
register: firewall_status
failed_when: false

Comment on lines +110 to +114
- name: Ensure Podman is installed if missing (Fixable)
package:
name: podman
state: present
when: not podman_installed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cephadm-preflight.yml already handles podman installation

Suggested change
- name: Ensure Podman is installed if missing (Fixable)
package:
name: podman
state: present
when: not podman_installed

Comment on lines +260 to +262
- name: Extract NIC Details
set_fact:
nic_config_details: "{{ ansible_facts['interfaces'] }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task is unnecessary, just use ansible_facts['interfaces'] directly wherever you need it

Suggested change
- name: Extract NIC Details
set_fact:
nic_config_details: "{{ ansible_facts['interfaces'] }}"

Comment on lines +268 to +271
- name: Identify Front-End and Back-End NICs
set_fact:
frontend_nic: "{{ ansible_facts['default_ipv4']['interface'] | default('Unknown') }}"
backend_nic: "{{ ansible_facts['interfaces'] | difference(['lo', ansible_facts['default_ipv4']['interface']]) | first | default(ansible_facts['default_ipv4']['interface']) }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task feels a bit awkward; that's not something Ansible can predict for you

Suggested change
- name: Identify Front-End and Back-End NICs
set_fact:
frontend_nic: "{{ ansible_facts['default_ipv4']['interface'] | default('Unknown') }}"
backend_nic: "{{ ansible_facts['interfaces'] | difference(['lo', ansible_facts['default_ipv4']['interface']]) | first | default(ansible_facts['default_ipv4']['interface']) }}"

I'd simply list all available network interfaces along with their link speed 🤷‍♂️

Comment on lines +302 to +305
- name: Read Preflight Check Report
slurp:
src: ./ceph_preflight_report.txt
register: report_content
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this task really needed? By the way, it's probably missing a delegate_to: localhost so I suspect it would fail.

please, have a look at loopkup('template') instead

@@ -0,0 +1,314 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd keep consistency and rename that file : preflight-checks.yml ( _ -> - )

Comment on lines +7 to +8
- name: Gather all Ansible facts
setup:
Copy link
Collaborator

@guits guits Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of the following if you make it an actual playbook with gather_facts: true

Suggested change
- name: Gather all Ansible facts
setup:

Comment on lines +83 to +84
firewalld_check: "{{ 'PASS' if firewall_status.status.ActiveState == 'active' else 'FAIL' }}"
firewalld_reason: "{{ 'Firewalld was not running and could not be started' if firewall_status.failed else 'N/A' }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate?

Suggested change
firewalld_check: "{{ 'PASS' if firewall_status.status.ActiveState == 'active' else 'FAIL' }}"
firewalld_reason: "{{ 'Firewalld was not running and could not be started' if firewall_status.failed else 'N/A' }}"

Comment on lines +43 to +44
selinux_check: "{{ 'PASS' if ansible_facts['selinux']['status'] == 'enabled' and ansible_facts['selinux']['mode'] == 'enforcing' else 'FAIL' }}"
selinux_reason: "{{ 'SELinux was not in enforcing mode and could not be enforced automatically' if selinux_check == 'FAIL' else 'N/A' }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate?

Suggested change
selinux_check: "{{ 'PASS' if ansible_facts['selinux']['status'] == 'enabled' and ansible_facts['selinux']['mode'] == 'enforcing' else 'FAIL' }}"
selinux_reason: "{{ 'SELinux was not in enforcing mode and could not be enforced automatically' if selinux_check == 'FAIL' else 'N/A' }}"

Comment on lines +88 to +90
- name: Collect installed package facts
package_facts:
manager: auto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this task to the beginning of the playbook

Comment on lines +28 to +31
- name: Retrieve SELinux status from ansible_facts
setup:
gather_subset:
- selinux
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Retrieve SELinux status from ansible_facts
setup:
gather_subset:
- selinux

Comment on lines +283 to +288
- name: Ping all hosts in inventory
ansible.builtin.ping:
register: ping_results
failed_when: false
delegate_to: "{{ item }}"
with_items: "{{ groups['all'] }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't give you the latency like an actual ICMP ping would.
This is just an Ansible module called 'ping', used to check if Ansible is able to connect to nodes.

Comment on lines +49 to +50
- name: Run checks
import_tasks: preflight_checks.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Run checks
import_tasks: preflight_checks.yml
- name: variables validations
ansible.builtin.import_playbook: validate/preflight.yml

setup:

- name: Check if OS is RHEL 9+
set_fact:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, use FQCN everywhere:

Suggested change
set_fact:
ansible.builtin.set_fact:

@guits
Copy link
Collaborator

guits commented Feb 18, 2025

@Kushal-deb Please consider using a single set_fact task, like the following, instead of multiple set_fact tasks for each check:

    - name: Store all check results
      set_fact:
        preflight_results: >-
          {{ preflight_results + [
            {'Check': 'OS Version', 'Result': os_check, 'Reason': os_reason},
            {'Check': 'Tuned Profile', 'Result': tuned_profile_check, 'Reason': tuned_profile_reason},
            {'Check': 'RHEL Profile', 'Result': rhel_profile_check, 'Reason': rhel_profile_reason},
            {'Check': 'Firewalld Running', 'Result': firewalld_check, 'Reason': firewalld_reason},
            {'Check': 'Podman Installed', 'Result': podman_check, 'Reason': podman_reason},
            {'Check': 'SELinux', 'Result': selinux_check, 'Reason': selinux_reason},
            {'Check': 'Minimum RAM (8GB)', 'Result': memory_checks['ram']['result'], 'Reason': memory_checks['ram']['reason']},
            {'Check': 'Swap Space (1.5x RAM)', 'Result': memory_checks['swap']['result'], 'Reason': memory_checks['swap']['reason']},
            {'Check': 'CPU x86-64-v2', 'Result': cpu_checks['x86_64_v2']['result'], 'Reason': cpu_checks['x86_64_v2']['reason']},
            {'Check': 'CPU Cores >= 4', 'Result': cpu_checks['cores']['result'], 'Reason': cpu_checks['cores']['reason']},
            {'Check': '/var is a separate partition', 'Result': filesystem_checks['var_partition']['result'], 'Reason': filesystem_checks['var_partition']['reason']},
            {'Check': 'Root Filesystem >= 100GB', 'Result': filesystem_checks['root_fs']['result'], 'Reason': filesystem_checks['root_fs']['reason']},
            {'Check': 'SELinux', 'Result': selinux_check, 'Reason': selinux_reason},
            {'Check': 'Jumbo Frames Enabled', 'Result': jumbo_frames_check, 'Reason': jumbo_frames_reason},
            {'Check': 'Network Latency', 'Result': 'INFO', 'Reason': 'Latency results: ' ~ ping_results.results | map(attribute='ping') | list},
            {'Check': 'NIC Static IP Configuration', 'Result': nic_config_check, 'Reason': nic_config_reason},
            {'Check': 'NIC Bandwidth (10GbE Recommended)', 'Result': nic_speed_check, 'Reason': nic_speed_reason},

          ] }}
        preflight_failures: >-
          {{ preflight_failures
             + (['OS Version'] if os_check == 'FAIL' else [])
             + (['Tuned Profile'] if tuned_profile_check == 'FAIL' else [])
             + (['RHEL Profile'] if rhel_profile_check == 'FAIL' else [])
             + (['SELinux'] if selinux_check == 'FAIL' else [])
             + (['Firewalld Running'] if firewalld_check == 'FAIL' else [])
             + (['Podman Installed'] if not podman_installed else [])
             + (['Minimum RAM'] if memory_checks['ram']['result'] == 'FAIL' else [])
             + (['Swap Space'] if memory_checks['swap']['result'] == 'FAIL' else [])
             + (['CPU x86-64-v2'] if cpu_checks['x86_64_v2']['result'] == 'FAIL' else [])
             + (['CPU Cores'] if cpu_checks['cores']['result'] == 'FAIL' else [])
             + (['/var Partition'] if filesystem_checks['var_partition']['result'] == 'FAIL' else [])
             + (['Root Filesystem'] if filesystem_checks['root_fs']['result'] == 'FAIL' else [])
             + (['SELinux'] if selinux_check == 'FAIL' else []) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants