Skip to content

Commit

Permalink
Fixed sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rajshekarp87 committed Dec 23, 2024
1 parent cab7538 commit a2535bd
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 170 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ You may obtain a copy of the License at
| -------------------------------------------------------------------------------------------- |
| [omevv_baseline_profile](modules/omevv_baseline_profile.rst) |
| [omevv_baseline_profile_info](modules/omevv_baseline_profile_info.rst) |
| [omevv_firmware](modules/omevv/omevv_firmware.rst) |
| [omevv_firmware](modules/omevv_firmware.rst) |
| [omevv_firmware_compliance_info](modules/omevv_firmware_compliance_info.rst) |
| [omevv_firmware_repository_profile](modules/omevv_firmware_repository_profile.rst) |
| [omevv_firmware_repository_profile_info](modules/omevv_firmware_repository_profile_info.rst) |
Expand Down
126 changes: 126 additions & 0 deletions playbooks/omevv/omevv_firmware.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
- name: Immediately update the firmware of a single component for a specific host
dellemc.openmanage.omevv.omevv_firmware:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
run_now: false
date_time: "2024-09-10T20:50:00Z"
enter_maintenance_mode_timeout: 60
enter_maintenance_mode_options: FULL_DATA_MIGRATION
drs_check: true
evacuate_VMs: true
exit_maintenance_mode: true
reboot_options: NEXTREBOOT
maintenance_mode_count_check: true
check_vSAN_health: true
reset_idrac: true
delete_job_queue: true
targets:
- servicetag: SVCTAG1
firmware_components:
- "DCIM:INSTALLED#802__Diagnostics.Embedded.1:LC.Embedded.1"
delegate_to: localhost

- name: Update the firmware of multiple components at scheduled time for a specific host
dellemc.openmanage.omevv.omevv_firmware:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
run_now: false
date_time: "2024-09-10T20:50:00+05:30"
enter_maintenance_mode_timeout: 60
enter_maintenance_mode_options: ENSURE_ACCESSIBILITY
drs_check: true
evacuate_VMs: true
exit_maintenance_mode: true
reboot_options: FORCEREBOOT
maintenance_mode_count_check: true
check_vSAN_health: true
reset_idrac: false
delete_job_queue: false
targets:
- host: 192.168.0.2
firmware_components:
- "DCIM:INSTALLED#iDRAC.Embedded.1-1#IDRACinfo"
- "DCIM:INSTALLED#301_C_BOSS.SL.14-1"
- "DCIM:INSTALLED#807__TPM.Integrated.1-1"
delegate_to: localhost

- name: Update the firmware of multiple components at scheduled time for a cluster
dellemc.openmanage.omevv.omevv_firmware:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
run_now: false
date_time: "2024-09-10T20:50:00+05:30"
enter_maintenance_mode_timeout: 60
enter_maintenance_mode_options: ENSURE_ACCESSIBILITY
drs_check: true
evacuate_VMs: true
exit_maintenance_mode: true
reboot_options: SAFEREBOOT
maintenance_mode_count_check: true
check_vSAN_health: true
reset_idrac: false
delete_job_queue: false
targets:
- cluster: cluster_a
firmware_components:
- "DCIM:INSTALLED#iDRAC.Embedded.1-1#IDRACinfo"
- "DCIM:INSTALLED#301_C_BOSS.SL.14-1"
- "DCIM:INSTALLED#807__TPM.Integrated.1-1"
delegate_to: localhost

- name: Retrieve firmware compliance report of all the hosts in the specific cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
register: compliance_data
delegate_to: localhost

- name: Extract source name of all components
ansible.builtin.set_fact:
source_names: "{{ compliance_data.hostComplianceReports[0].componentCompliances|json_query('*.sourceName') }}"
delegate_to: localhost

- name: Extract source name of a specific component
ansible.builtin.set_fact:
source_name: "{{ compliance_data.hostComplianceReports[0].componentCompliances[0].sourceName }}"
delegate_to: localhost

- name: Update firmware at the scheduled time for a specific host
dellemc.openmanage.omevv.omevv_firmware:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
run_now: false
date_time: "2024-09-10T20:50:00Z"
enter_maintenance_mode_timeout: 60
enter_maintenance_mode_options: NO_DATA_MIGRATION
drs_check: true
evacuate_VMs: false
exit_maintenance_mode: true
reboot_options: SAFEREBOOT
maintenance_mode_count_check: true
check_vSAN_health: true
reset_idrac: true
delete_job_queue: true
targets:
- servicetag: SVCTAG1
firmware_components:
- "{{ source_name }}"
delegate_to: localhost
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- name: Fetch firmware version
ansible.builtin.uri:
url: "https://{{ idrac_ip|ansible.utils.ipwrap }}:{{ idrac_port }}/redfish/v1/Managers/iDRAC.Embedded.1"
url: "https://{{ idrac_ip|ansible.utils.ipwrap }}:{{ idrac_port }}
/redfish/v1/Managers/iDRAC.Embedded.1"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Ensure private key is present
community.crypto.openssl_privatekey:
path: "{{ base_path_for_import_certificate }}/cert.key"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
- name: Download files
ansible.builtin.get_url:
url: "http://{{ https_share_ip }}{{ https_certificate_path }}{{ item.value }}"
url: "http://{{ https_share_ip }}{{ https_certificate_path }}
{{ item.value }}"
dest: "{{ base_path_for_import_certificate }}/{{ item.value }}"
headers:
Authorization: "Basic {{ (https_share_username + ':' + https_share_password) | b64encode }}"
Authorization: "Basic {{ (
https_share_username + ':' + https_share_password) | b64encode }}"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- ansible.builtin.set_fact:
cert_type: "{{ item.value }}"

Expand All @@ -9,15 +10,17 @@
dellemc.openmanage.idrac_certificates:
command: import
certificate_type: "{{ cert_type }}"
certificate_path: "{{ base_path_for_import_certificate }}/{{ certificate_path }}"
certificate_path: "{{ base_path_for_import_certificate }}/{{
certificate_path }}"
register: import_certificate_output
when: 'cert_type != "HTTPS"'

- ansible.builtin.include_tasks: _wait_for_idrac_readiness.yml
when: 'cert_type != "HTTPS"'

- ansible.builtin.set_fact:
import_successful_msg: "Successfully performed the 'import' certificate operation.iDRAC has been reset successfully."
import_successful_msg: "Successfully performed the 'import' certificate operation.iDRAC
has been reset successfully."
when: 'cert_type != "HTTPS"'

- name: Verify status of task - import certificate
Expand All @@ -28,8 +31,9 @@

- ansible.builtin.include_tasks: get_data_uri.yml
vars:
url: "https://{{ idrac_ip | ansible.utils.ipwrap }}:{{ idrac_port }}/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell\
/DelliDRACCardService/Actions/DelliDRACCardService.ExportSSLCertificate"
url: "https://{{ idrac_ip | ansible.utils.ipwrap }}:{{
idrac_port }}/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell\
/DelliDRACCardService/Actions/DelliDRACCardService.ExportSSLCertificate"
body:
SSLCertType: "{{ item.key }}"

Expand All @@ -53,7 +57,8 @@
register: export_certificate_output

- ansible.builtin.set_fact:
export_successful_msg: "Successfully performed the 'export' certificate operation."
export_successful_msg: "Successfully performed the 'export' certificate
operation."

- name: Verify status of task - export certificate
ansible.builtin.assert:
Expand All @@ -66,10 +71,12 @@
register: certificate_filename

- ansible.builtin.set_fact:
certificate: "{{ export_certificate_path }}/{{ certificate_filename.stdout }}"
certificate: "{{ export_certificate_path }}/{{
certificate_filename.stdout }}"

- ansible.builtin.set_fact:
certificate_content_from_module: "{{ lookup('ansible.builtin.file', '{{ certificate }}',rstrip=False) }}"
certificate_content_from_module: "{{ lookup('ansible.builtin.file',
'{{ certificate }}',rstrip=False) }}"

- name: Verify content of certificate
ansible.builtin.assert:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- ansible.builtin.set_fact:
certificate_path: "{{ base_path_for_import_certificate }}/{{ item.value }}"

Expand Down Expand Up @@ -26,7 +27,8 @@
- ansible.builtin.include_tasks: _wait_for_idrac_readiness.yml

- ansible.builtin.set_fact:
import_successful_msg: "Successfully performed the 'import' certificate operation.iDRAC has been reset successfully."
import_successful_msg: "Successfully performed the 'import' certificate
operation.iDRAC has been reset successfully."

- name: Verify status of task - import certificate - normal mode
ansible.builtin.assert:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Wait for port to become open on the host
ansible.builtin.wait_for:
host: "{{ idrac_ip }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
- block:
- name: ansible-doc
command: ansible-doc dellemc.openmanage.idrac_certificates
register: ansible_doc_hash

- local_action: copy content={{ansible_doc_hash.stdout_lines[2:] | to_nice_yaml}} dest={{ role_path }}/files/ansible_doc.txt
- local_action: copy content={{ansible_doc_hash.stdout_lines[2:] |
to_nice_yaml}} dest={{ role_path }}/files/ansible_doc.txt
register: ansible_doc
check_mode: true
diff: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Test code for the Dell OpenManage modules
# Copyright (C) 2023 - 2024 Dell Inc. or its subsidiaries. All Rights Reserved.

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Dell OpenManage Ansible modules
# Copyright (C) 2024 Dell Inc. or its subsidiaries. All Rights Reserved.

# GNU General Public License v3.0+ (see COPYING or
# https://www.gnu.org/licenses/gpl-3.0.txt)
---
- name: Test that we have an iDRAC host, iDRAC username and iDRAC password
ansible.builtin.fail:
msg: "Please define the following variables: idrac_ip, idrac_user and idrac_password."
when: idrac_ip is not defined or idrac_user is not defined or idrac_password is not defined
msg: 'Please define the following variables: idrac_ip, idrac_user and
idrac_password.'
when: 'idrac_ip is not defined or idrac_user is not defined or idrac_password
is not defined'

- name: Verify iDRAC Certificate Signing Request
module_defaults:
Expand Down Expand Up @@ -61,10 +64,13 @@
ansible.builtin.assert:
that:
- not generate_csr_cm.changed
- generate_csr_cm.msg == "Successfully performed the 'generate_csr' certificate operation."
- generate_csr_cm.msg == "Successfully performed the 'generate_csr'
certificate operation."
- file_status_cm.stat.exists
- (generate_csr_cm.certificate_path | basename).startswith(idrac_ip)
- (generate_csr_cm.certificate_path | basename).endswith("_"+ cert_type + ".txt")
- (generate_csr_cm.certificate_path |
basename).startswith(idrac_ip)
- (generate_csr_cm.certificate_path |
basename).endswith("_"+ cert_type + ".txt")

- name: Get CSR info check mode
community.crypto.openssl_csr_info:
Expand All @@ -81,7 +87,8 @@
- csr_content_cm.subject.stateOrProvinceName == stateOrProvinceName
- csr_content_cm.subject.countryName == countryName
- csr_content_cm.subject.emailAddress == emailAddress
- (csr_content_cm.subject_alt_name | length) == (sub_alt_name_list | length)
- (csr_content_cm.subject_alt_name |
length) == (sub_alt_name_list | length)

- name: Verify CSR SAN check mode
ansible.builtin.assert:
Expand All @@ -105,10 +112,13 @@
ansible.builtin.assert:
that:
- not generate_csr.changed
- generate_csr.msg == "Successfully performed the 'generate_csr' certificate operation."
- generate_csr.msg == "Successfully performed
the 'generate_csr' certificate operation."
- file_status.stat.exists
- (generate_csr.certificate_path | basename).startswith(idrac_ip)
- (generate_csr.certificate_path | basename).endswith("_"+ cert_type + ".txt")
- (generate_csr.certificate_path |
basename).startswith(idrac_ip)
- (generate_csr.certificate_path |
basename).endswith("_"+ cert_type + ".txt")

- name: Get CSR info all parameters
community.crypto.openssl_csr_info:
Expand All @@ -125,7 +135,8 @@
- csr_content.subject.stateOrProvinceName == stateOrProvinceName
- csr_content.subject.countryName == countryName
- csr_content.subject.emailAddress == emailAddress
- (csr_content.subject_alt_name | length) == (sub_alt_name_list | length)
- (csr_content.subject_alt_name |
length) == (sub_alt_name_list | length)

- name: Verify CSR SAN all parameters
ansible.builtin.assert:
Expand Down Expand Up @@ -158,10 +169,13 @@
ansible.builtin.assert:
that:
- not generate_csr_mp.changed
- generate_csr_mp.msg == "Successfully performed the 'generate_csr' certificate operation."
- generate_csr_mp.msg == "Successfully performed
the 'generate_csr' certificate operation."
- file_status_mp.stat.exists
- (generate_csr_mp.certificate_path | basename).startswith(idrac_ip)
- (generate_csr_mp.certificate_path | basename).endswith("_"+ cert_type + ".txt")
- (generate_csr_mp.certificate_path |
basename).startswith(idrac_ip)
- (generate_csr_mp.certificate_path |
basename).endswith("_"+ cert_type + ".txt")

- name: Get CSR info mandatory parameters
community.crypto.openssl_csr_info:
Expand All @@ -172,7 +186,8 @@
ansible.builtin.assert:
that:
- csr_content_mp.subject.commonName == commonName
- csr_content_mp.subject.organizationalUnitName == organizationalUnitName
- csr_content_mp.subject.organizationalUnitName == organizational
UnitName
- csr_content_mp.subject.organizationName == organizationName
- csr_content_mp.subject.localityName == localityName
- csr_content_mp.subject.stateOrProvinceName == stateOrProvinceName
Expand Down
Loading

0 comments on commit a2535bd

Please sign in to comment.