From 2119ffc9324fca012581cfb591bf66c94afafb88 Mon Sep 17 00:00:00 2001 From: Josh Eisenbath Date: Wed, 11 Sep 2024 18:46:03 -0500 Subject: [PATCH 1/2] Add support for ldap, network connectivity, sd card, smtp, ssh policies. Minor rewrite for less code when adding new policy params. --- plugins/modules/intersight_server_profile.py | 96 ++++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/plugins/modules/intersight_server_profile.py b/plugins/modules/intersight_server_profile.py index 16a4e76..30877f0 100644 --- a/plugins/modules/intersight_server_profile.py +++ b/plugins/modules/intersight_server_profile.py @@ -96,10 +96,18 @@ description: - Name of LAN Connectivity Policy to associate with this profile. type: str + ldap_policy: + description: + - Name of LDAP Policy to associate with this profile. + type: str local_user_policy: description: - Name of Local User Policy to associate with this profile. type: str + network_connectivity_policy: + description: + - Name of Network Connectivity Policy to associate with this profile. + type: str ntp_policy: description: - Name of NTP Policy to associate with this profile. @@ -112,14 +120,26 @@ description: - Name of SAN Connectivity Policy to associate with this profile. type: str + sd_card_policy: + description: + - Name of SD Card Policy to associate with this profile. + type: str serial_over_lan_policy: description: - Name of Serial over LAN Policy to associate with this profile. type: str + smtp_policy: + description: + - Name of SMTP Policy to associate with this profile. + type: str snmp_policy: description: - Name of SNMP Policy to associate with this profile. type: str + ssh_policy: + description: + - Name of SSH Policy to associate with this profile. + type: str storage_policy: description: - Name of Storage Policy to associate with this profile. @@ -204,6 +224,35 @@ from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec +# When adding new policy parameters, update this dict with their respective resource path +policy_resource_path = { + 'bios_policy': '/bios/Policies', + 'boot_order_policy': '/boot/PrecisionPolicies', + 'certificate_policy': '/certificatemanagement/Policies', + 'drive_security_policy': '/storage/DriveSecurityPolicies', + 'firmware_policy': '/firmware/Policies', + 'imc_access_policy': '/access/Policies', + 'ipmi_over_lan_policy': '/ipmioverlan/Policies', + 'lan_connectivity_policy': '/vnic/LanConnectivityPolicies', + 'local_user_policy': '/iam/EndPointUserPolicies', + 'ldap_policy': '/iam/LdapPolicies', + 'network_connectivity_policy': '/networkconfig/Policies', + 'ntp_policy': '/ntp/Policies', + 'power_policy': '/power/Policies', + 'san_connectivity_policy': '/vnic/SanConnectivityPolicies', + 'sd_card_policy': '/sdcard/Policies', + 'serial_over_lan_policy': '/sol/Policies', + 'smtp_policy': '/smtp/Policies', + 'snmp_policy': '/snmp/Policies', + 'ssh_policy': '/ssh/Policies', + 'storage_policy': '/storage/StoragePolicies', + 'syslog_policy': '/syslog/Policies', + 'thermal_policy': '/thermal/Policies', + 'virtual_kvm_policy': '/kvm/Policies', + 'virtual_media_policy': '/vmedia/Policies', +} + + def post_profile_to_policy(intersight, moid, resource_path, policy_name): options = { 'http_method': 'get', @@ -274,12 +323,17 @@ def main(): imc_access_policy=dict(type='str'), ipmi_over_lan_policy=dict(type='str'), lan_connectivity_policy=dict(type='str'), + ldap_policy=dict(type='str'), local_user_policy=dict(type='str'), + network_connectivity_policy=dict(type='str'), ntp_policy=dict(type='str'), power_policy=dict(type='str'), san_connectivity_policy=dict(type='str'), + sd_card_policy=dict(type='str'), serial_over_lan_policy=dict(type='str'), + smtp_policy=dict(type='str'), snmp_policy=dict(type='str'), + ssh_policy=dict(type='str'), storage_policy=dict(type='str'), syslog_policy=dict(type='str'), thermal_policy=dict(type='str'), @@ -330,44 +384,10 @@ def main(): # Configure the profile moid = intersight.configure_policy_or_profile(resource_path=resource_path) - if moid and intersight.module.params['bios_policy']: - post_profile_to_policy(intersight, moid, resource_path='/bios/Policies', policy_name=intersight.module.params['bios_policy']) - if moid and intersight.module.params['boot_order_policy']: - post_profile_to_policy(intersight, moid, resource_path='/boot/PrecisionPolicies', policy_name=intersight.module.params['boot_order_policy']) - if moid and intersight.module.params['certificate_policy']: - post_profile_to_policy(intersight, moid, resource_path='/certificatemanagement/Policies', policy_name=intersight.module.params['certificate_policy']) - if moid and intersight.module.params['drive_security_policy']: - post_profile_to_policy(intersight, moid, resource_path='/storage/DriveSecurityPolicies', policy_name=intersight.module.params['drive_security_policy']) - if moid and intersight.module.params['firmware_policy']: - post_profile_to_policy(intersight, moid, resource_path='/firmware/Policies', policy_name=intersight.module.params['firmware_policy']) - if moid and intersight.module.params['imc_access_policy']: - post_profile_to_policy(intersight, moid, resource_path='/access/Policies', policy_name=intersight.module.params['imc_access_policy']) - if moid and intersight.module.params['ipmi_over_lan_policy']: - post_profile_to_policy(intersight, moid, resource_path='/ipmioverlan/Policies', policy_name=intersight.module.params['ipmi_over_lan_policy']) - if moid and intersight.module.params['lan_connectivity_policy']: - post_profile_to_policy(intersight, moid, resource_path='/vnic/LanConnectivityPolicies', policy_name=intersight.module.params['lan_connectivity_policy']) - if moid and intersight.module.params['local_user_policy']: - post_profile_to_policy(intersight, moid, resource_path='/iam/EndPointUserPolicies', policy_name=intersight.module.params['local_user_policy']) - if moid and intersight.module.params['ntp_policy']: - post_profile_to_policy(intersight, moid, resource_path='/ntp/Policies', policy_name=intersight.module.params['ntp_policy']) - if moid and intersight.module.params['power_policy']: - post_profile_to_policy(intersight, moid, resource_path='/power/Policies', policy_name=intersight.module.params['power_policy']) - if moid and intersight.module.params['san_connectivity_policy']: - post_profile_to_policy(intersight, moid, resource_path='/vnic/SanConnectivityPolicies', policy_name=intersight.module.params['san_connectivity_policy']) - if moid and intersight.module.params['serial_over_lan_policy']: - post_profile_to_policy(intersight, moid, resource_path='/sol/Policies', policy_name=intersight.module.params['serial_over_lan_policy']) - if moid and intersight.module.params['snmp_policy']: - post_profile_to_policy(intersight, moid, resource_path='/snmp/Policies', policy_name=intersight.module.params['snmp_policy']) - if moid and intersight.module.params['storage_policy']: - post_profile_to_policy(intersight, moid, resource_path='/storage/StoragePolicies', policy_name=intersight.module.params['storage_policy']) - if moid and intersight.module.params['syslog_policy']: - post_profile_to_policy(intersight, moid, resource_path='/syslog/Policies', policy_name=intersight.module.params['syslog_policy']) - if moid and intersight.module.params['thermal_policy']: - post_profile_to_policy(intersight, moid, resource_path='/thermal/Policies', policy_name=intersight.module.params['thermal_policy']) - if moid and intersight.module.params['virtual_kvm_policy']: - post_profile_to_policy(intersight, moid, resource_path='/kvm/Policies', policy_name=intersight.module.params['virtual_kvm_policy']) - if moid and intersight.module.params['virtual_media_policy']: - post_profile_to_policy(intersight, moid, resource_path='/vmedia/Policies', policy_name=intersight.module.params['virtual_media_policy']) + if moid: + for k, v in policy_resource_path.items(): + if intersight.module.params[k]: + post_profile_to_policy(intersight, moid, resource_path=v, policy_name=intersight.module.params[k]) module.exit_json(**intersight.result) From e37d8916589ba25a03596e60238df52d67909e4f Mon Sep 17 00:00:00 2001 From: Josh Eisenbath Date: Wed, 11 Sep 2024 18:46:15 -0500 Subject: [PATCH 2/2] update example playbook with new params --- playbooks/intersight_server_profile.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/playbooks/intersight_server_profile.yml b/playbooks/intersight_server_profile.yml index 811f8b5..a6ba9a6 100644 --- a/playbooks/intersight_server_profile.yml +++ b/playbooks/intersight_server_profile.yml @@ -54,12 +54,17 @@ imc_access_policy: "{{ imc_access_policy | default(omit) }}" ipmi_over_lan_policy: "{{ ipmi_over_lan_policy | default(omit) }}" lan_connectivity_policy: "{{ lan_connectivity_policy | default(omit) }}" + ldap_policy: "{{ ldap_policy | default(omit) }}" local_user_policy: "{{ local_user_policy | default(omit) }}" + network_connectivity_policy: "{{ network_connectivity_policy | default(omit) }}" ntp_policy: "{{ ntp_policy | default(omit) }}" power_policy: "{{ power_policy | default(omit) }}" san_connectivity_policy: "{{ san_connectivity_policy | default(omit) }}" + sd_card_policy: "{{ sd_card_policy | default(omit) }}" serial_over_lan_policy: "{{ serial_over_lan_policy | default(omit) }}" + smtp_policy: "{{ smtp_policy | default(omit) }}" snmp_policy: "{{ snmp_policy | default(omit) }}" + ssh_policy: "{{ ssh_policy | default(omit) }}" storage_policy: "{{ storage_policy | default(omit) }}" syslog_policy: "{{ syslog_policy | default(omit) }}" thermal_policy: "{{ thermal_policy | default(omit) }}"