| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from __future__ import (absolute_import, division, print_function) |
| 14 |
|
| 15 |
__metaclass__ = type |
| 16 |
|
| 17 |
DOCUMENTATION = """ |
| 18 |
--- |
| 19 |
module: dellemc_configure_idrac_services |
| 20 |
short_description: Configures the iDRAC services related attributes |
| 21 |
version_added: "1.0.0" |
| 22 |
deprecated: |
| 23 |
removed_at_date: "2024-12-31" |
| 24 |
why: Replaced with M(dellemc.openmanage.idrac_attributes). |
| 25 |
alternative: Use M(dellemc.openmanage.idrac_attributes) instead. |
| 26 |
removed_from_collection: dellemc.openmanage |
| 27 |
description: |
| 28 |
- This module allows to configure the iDRAC services related attributes. |
| 29 |
options: |
| 30 |
idrac_ip: |
| 31 |
required: true |
| 32 |
type: str |
| 33 |
description: iDRAC IP Address. |
| 34 |
idrac_user: |
| 35 |
required: true |
| 36 |
type: str |
| 37 |
description: iDRAC username. |
| 38 |
idrac_password: |
| 39 |
required: true |
| 40 |
type: str |
| 41 |
description: iDRAC user password. |
| 42 |
aliases: ['idrac_pwd'] |
| 43 |
idrac_port: |
| 44 |
type: int |
| 45 |
description: iDRAC port. |
| 46 |
default: 443 |
| 47 |
validate_certs: |
| 48 |
description: |
| 49 |
- If C(false), the SSL certificates will not be validated. |
| 50 |
- Configure C(false) only on personally controlled sites where self-signed certificates are used. |
| 51 |
- Prior to collection version C(5.0.0), the I(validate_certs) is C(false) by default. |
| 52 |
type: bool |
| 53 |
default: true |
| 54 |
version_added: 5.0.0 |
| 55 |
ca_path: |
| 56 |
description: |
| 57 |
- The Privacy Enhanced Mail (PEM) file that contains a CA certificate to be used for the validation. |
| 58 |
type: path |
| 59 |
version_added: 5.0.0 |
| 60 |
share_name: |
| 61 |
type: str |
| 62 |
description: |
| 63 |
- (deprecated)Network share or a local path. |
| 64 |
- This option is deprecated and will be removed in the later version. |
| 65 |
share_user: |
| 66 |
type: str |
| 67 |
description: |
| 68 |
- (deprecated)Network share user in the format 'user@domain' or 'domain\\user' if user is |
| 69 |
part of a domain else 'user'. This option is mandatory for CIFS Network Share. |
| 70 |
- This option is deprecated and will be removed in the later version. |
| 71 |
share_password: |
| 72 |
type: str |
| 73 |
description: |
| 74 |
- (deprecated)Network share user password. This option is mandatory for CIFS Network Share. |
| 75 |
- This option is deprecated and will be removed in the later version. |
| 76 |
aliases: ['share_pwd'] |
| 77 |
share_mnt: |
| 78 |
type: str |
| 79 |
description: |
| 80 |
- (deprecated)Local mount path of the network share with read-write permission for ansible user. |
| 81 |
This option is mandatory for Network Share. |
| 82 |
- This option is deprecated and will be removed in the later version. |
| 83 |
enable_web_server: |
| 84 |
type: str |
| 85 |
description: Whether to Enable or Disable webserver configuration for iDRAC. |
| 86 |
choices: [Enabled, Disabled] |
| 87 |
ssl_encryption: |
| 88 |
type: str |
| 89 |
description: Secure Socket Layer encryption for webserver. |
| 90 |
choices: [Auto_Negotiate, T_128_Bit_or_higher, T_168_Bit_or_higher, T_256_Bit_or_higher] |
| 91 |
tls_protocol: |
| 92 |
type: str |
| 93 |
description: Transport Layer Security for webserver. |
| 94 |
choices: [TLS_1_0_and_Higher, TLS_1_1_and_Higher, TLS_1_2_Only] |
| 95 |
https_port: |
| 96 |
type: int |
| 97 |
description: HTTPS access port. |
| 98 |
http_port: |
| 99 |
type: int |
| 100 |
description: HTTP access port. |
| 101 |
timeout: |
| 102 |
type: str |
| 103 |
description: Timeout value. |
| 104 |
snmp_enable: |
| 105 |
type: str |
| 106 |
description: Whether to Enable or Disable SNMP protocol for iDRAC. |
| 107 |
choices: [Enabled, Disabled] |
| 108 |
snmp_protocol: |
| 109 |
type: str |
| 110 |
description: Type of the SNMP protocol. |
| 111 |
choices: [All, SNMPv3] |
| 112 |
community_name: |
| 113 |
type: str |
| 114 |
description: SNMP community name for iDRAC. It is used by iDRAC to validate SNMP queries |
| 115 |
received from remote systems requesting SNMP data access. |
| 116 |
alert_port: |
| 117 |
type: int |
| 118 |
description: The iDRAC port number that must be used for SNMP traps. |
| 119 |
The default value is 162, and the acceptable range is between 1 to 65535. |
| 120 |
default: 162 |
| 121 |
discovery_port: |
| 122 |
type: int |
| 123 |
description: The SNMP agent port on the iDRAC. The default value is 161, |
| 124 |
and the acceptable range is between 1 to 65535. |
| 125 |
default: 161 |
| 126 |
trap_format: |
| 127 |
type: str |
| 128 |
description: SNMP trap format for iDRAC. |
| 129 |
choices: [SNMPv1, SNMPv2, SNMPv3] |
| 130 |
ipmi_lan: |
| 131 |
type: dict |
| 132 |
description: Community name set on iDRAC for SNMP settings. |
| 133 |
suboptions: |
| 134 |
community_name: |
| 135 |
type: str |
| 136 |
description: This option is used by iDRAC when it sends out SNMP and IPMI traps. |
| 137 |
The community name is checked by the remote system to which the traps are sent. |
| 138 |
requirements: |
| 139 |
- "omsdk >= 1.2.488" |
| 140 |
- "python >= 3.9.6" |
| 141 |
author: "Felix Stephen (@felixs88)" |
| 142 |
notes: |
| 143 |
- This module requires 'Administrator' privilege for I(idrac_user). |
| 144 |
- Run this module from a system that has direct access to Dell iDRAC. |
| 145 |
- This module supports both IPv4 and IPv6 address for I(idrac_ip). |
| 146 |
- This module supports C(check_mode). |
| 147 |
""" |
| 148 |
|
| 149 |
EXAMPLES = """ |
| 150 |
--- |
| 151 |
- name: Configure the iDRAC services attributes |
| 152 |
dellemc.openmanage.dellemc_configure_idrac_services: |
| 153 |
idrac_ip: "192.168.0.1" |
| 154 |
idrac_user: "user_name" |
| 155 |
idrac_password: "user_password" |
| 156 |
ca_path: "/path/to/ca_cert.pem" |
| 157 |
enable_web_server: "Enabled" |
| 158 |
http_port: 80 |
| 159 |
https_port: 443 |
| 160 |
ssl_encryption: "Auto_Negotiate" |
| 161 |
tls_protocol: "TLS_1_2_Only" |
| 162 |
timeout: "1800" |
| 163 |
snmp_enable: "Enabled" |
| 164 |
snmp_protocol: "SNMPv3" |
| 165 |
community_name: "public" |
| 166 |
alert_port: 162 |
| 167 |
discovery_port: 161 |
| 168 |
trap_format: "SNMPv3" |
| 169 |
ipmi_lan: |
| 170 |
community_name: "public" |
| 171 |
""" |
| 172 |
|
| 173 |
RETURN = r''' |
| 174 |
--- |
| 175 |
msg: |
| 176 |
description: Overall status of iDRAC service attributes configuration. |
| 177 |
returned: always |
| 178 |
type: str |
| 179 |
sample: Successfully configured the iDRAC services settings. |
| 180 |
service_status: |
| 181 |
description: Details of iDRAC services attributes configuration. |
| 182 |
returned: success |
| 183 |
type: dict |
| 184 |
sample: { |
| 185 |
"CompletionTime": "2020-04-02T02:43:28", |
| 186 |
"Description": "Job Instance", |
| 187 |
"EndTime": null, |
| 188 |
"Id": "JID_12345123456", |
| 189 |
"JobState": "Completed", |
| 190 |
"JobType": "ImportConfiguration", |
| 191 |
"Message": "Successfully imported and applied Server Configuration Profile.", |
| 192 |
"MessageArgs": [], |
| 193 |
"MessageId": "SYS053", |
| 194 |
"Name": "Import Configuration", |
| 195 |
"PercentComplete": 100, |
| 196 |
"StartTime": "TIME_NOW", |
| 197 |
"Status": "Success", |
| 198 |
"TargetSettingsURI": null, |
| 199 |
"retval": true |
| 200 |
} |
| 201 |
error_info: |
| 202 |
description: Details of the HTTP Error. |
| 203 |
returned: on HTTP error |
| 204 |
type: dict |
| 205 |
sample: { |
| 206 |
"error": { |
| 207 |
"code": "Base.1.0.GeneralError", |
| 208 |
"message": "A general error has occurred. See ExtendedInfo for more information.", |
| 209 |
"@Message.ExtendedInfo": [ |
| 210 |
{ |
| 211 |
"MessageId": "GEN1234", |
| 212 |
"RelatedProperties": [], |
| 213 |
"Message": "Unable to process the request because an error occurred.", |
| 214 |
"MessageArgs": [], |
| 215 |
"Severity": "Critical", |
| 216 |
"Resolution": "Retry the operation. If the issue persists, contact your system administrator." |
| 217 |
} |
| 218 |
] |
| 219 |
} |
| 220 |
} |
| 221 |
''' |
| 222 |
|
| 223 |
import os |
| 224 |
import tempfile |
| 225 |
import json |
| 226 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection |
| 227 |
from ansible.module_utils.basic import AnsibleModule |
| 228 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 229 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 230 |
|
| 231 |
try: |
| 232 |
from omdrivers.enums.iDRAC.iDRAC import (Enable_WebServerTypes, |
| 233 |
SSLEncryptionBitLength_WebServerTypes, |
| 234 |
TLSProtocol_WebServerTypes, |
| 235 |
AgentEnable_SNMPTypes, |
| 236 |
SNMPProtocol_SNMPTypes) |
| 237 |
from omsdk.sdkfile import file_share_manager |
| 238 |
except ImportError: |
| 239 |
pass |
| 240 |
|
| 241 |
|
| 242 |
def run_idrac_services_config(idrac, module): |
| 243 |
""" |
| 244 |
Get Lifecycle Controller status |
| 245 |
|
| 246 |
Keyword arguments: |
| 247 |
idrac -- iDRAC handle |
| 248 |
module -- Ansible module |
| 249 |
""" |
| 250 |
idrac.use_redfish = True |
| 251 |
share_path = tempfile.gettempdir() + os.sep |
| 252 |
upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True) |
| 253 |
if not upd_share.IsValid: |
| 254 |
module.fail_json(msg="Unable to access the share. Ensure that the share name, " |
| 255 |
"share mount, and share credentials provided are correct.") |
| 256 |
set_liason = idrac.config_mgr.set_liason_share(upd_share) |
| 257 |
if set_liason['Status'] == "Failed": |
| 258 |
try: |
| 259 |
message = set_liason['Data']['Message'] |
| 260 |
except (IndexError, KeyError): |
| 261 |
message = set_liason['Message'] |
| 262 |
module.fail_json(msg=message) |
| 263 |
|
| 264 |
if module.params['enable_web_server'] is not None: |
| 265 |
idrac.config_mgr.configure_web_server( |
| 266 |
enable_web_server=Enable_WebServerTypes[module.params['enable_web_server']] |
| 267 |
) |
| 268 |
if module.params['http_port'] is not None: |
| 269 |
idrac.config_mgr.configure_web_server( |
| 270 |
http_port=module.params['http_port'] |
| 271 |
) |
| 272 |
if module.params['https_port'] is not None: |
| 273 |
idrac.config_mgr.configure_web_server( |
| 274 |
https_port=module.params['https_port'] |
| 275 |
) |
| 276 |
if module.params['timeout'] is not None: |
| 277 |
idrac.config_mgr.configure_web_server( |
| 278 |
timeout=module.params['timeout'] |
| 279 |
) |
| 280 |
if module.params['ssl_encryption'] is not None: |
| 281 |
idrac.config_mgr.configure_web_server( |
| 282 |
ssl_encryption=SSLEncryptionBitLength_WebServerTypes[module.params['ssl_encryption']] |
| 283 |
) |
| 284 |
if module.params['tls_protocol'] is not None: |
| 285 |
idrac.config_mgr.configure_web_server( |
| 286 |
tls_protocol=TLSProtocol_WebServerTypes[module.params['tls_protocol']] |
| 287 |
) |
| 288 |
|
| 289 |
if module.params['snmp_enable'] is not None: |
| 290 |
idrac.config_mgr.configure_snmp( |
| 291 |
snmp_enable=AgentEnable_SNMPTypes[module.params['snmp_enable']] |
| 292 |
) |
| 293 |
if module.params['community_name'] is not None: |
| 294 |
idrac.config_mgr.configure_snmp( |
| 295 |
community_name=module.params['community_name'] |
| 296 |
) |
| 297 |
if module.params['snmp_protocol'] is not None: |
| 298 |
idrac.config_mgr.configure_snmp( |
| 299 |
snmp_protocol=SNMPProtocol_SNMPTypes[module.params['snmp_protocol']] |
| 300 |
) |
| 301 |
if module.params['alert_port'] is not None: |
| 302 |
idrac.config_mgr.configure_snmp( |
| 303 |
alert_port=module.params['alert_port'] |
| 304 |
) |
| 305 |
if module.params['discovery_port'] is not None: |
| 306 |
idrac.config_mgr.configure_snmp( |
| 307 |
discovery_port=module.params['discovery_port'] |
| 308 |
) |
| 309 |
if module.params['trap_format'] is not None: |
| 310 |
idrac.config_mgr.configure_snmp( |
| 311 |
trap_format=module.params['trap_format'] |
| 312 |
) |
| 313 |
if module.params['ipmi_lan'] is not None: |
| 314 |
ipmi_option = module.params.get('ipmi_lan') |
| 315 |
community_name = ipmi_option.get('community_name') |
| 316 |
if community_name is not None: |
| 317 |
idrac.config_mgr.configure_snmp(ipmi_community=community_name) |
| 318 |
|
| 319 |
if module.check_mode: |
| 320 |
status = idrac.config_mgr.is_change_applicable() |
| 321 |
if status.get('changes_applicable'): |
| 322 |
module.exit_json(msg="Changes found to commit!", changed=True) |
| 323 |
else: |
| 324 |
module.exit_json(msg="No changes found to commit!") |
| 325 |
else: |
| 326 |
return idrac.config_mgr.apply_changes(reboot=False) |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
def main(): |
| 331 |
module = AnsibleModule( |
| 332 |
argument_spec=dict( |
| 333 |
|
| 334 |
|
| 335 |
idrac_ip=dict(required=True, type='str'), |
| 336 |
idrac_user=dict(required=True, type='str'), |
| 337 |
idrac_password=dict(required=True, type='str', aliases=['idrac_pwd'], no_log=True), |
| 338 |
idrac_port=dict(required=False, default=443, type='int'), |
| 339 |
validate_certs=dict(type='bool', default=True), |
| 340 |
ca_path=dict(type='path'), |
| 341 |
|
| 342 |
share_name=dict(required=False, type='str'), |
| 343 |
share_password=dict(required=False, type='str', aliases=['share_pwd'], no_log=True), |
| 344 |
share_user=dict(required=False, type='str'), |
| 345 |
share_mnt=dict(required=False, type='str'), |
| 346 |
|
| 347 |
|
| 348 |
enable_web_server=dict(required=False, choices=['Enabled', 'Disabled'], default=None), |
| 349 |
http_port=dict(required=False, default=None, type='int'), |
| 350 |
https_port=dict(required=False, default=None, type='int'), |
| 351 |
ssl_encryption=dict(required=False, choices=['Auto_Negotiate', 'T_128_Bit_or_higher', |
| 352 |
'T_168_Bit_or_higher', 'T_256_Bit_or_higher'], |
| 353 |
default=None), |
| 354 |
tls_protocol=dict(required=False, choices=['TLS_1_0_and_Higher', |
| 355 |
'TLS_1_1_and_Higher', 'TLS_1_2_Only'], default=None), |
| 356 |
timeout=dict(required=False, default=None, type="str"), |
| 357 |
|
| 358 |
|
| 359 |
snmp_enable=dict(required=False, choices=['Enabled', 'Disabled'], default=None), |
| 360 |
community_name=dict(required=False, type='str'), |
| 361 |
snmp_protocol=dict(required=False, choices=['All', 'SNMPv3'], default=None), |
| 362 |
discovery_port=dict(required=False, type="int", default=161), |
| 363 |
|
| 364 |
|
| 365 |
ipmi_lan=dict(required=False, type='dict', options=dict(community_name=dict(required=False, type='str'))), |
| 366 |
alert_port=dict(required=False, type='int', default=162), |
| 367 |
trap_format=dict(required=False, choices=['SNMPv1', 'SNMPv2', 'SNMPv3'], default=None), |
| 368 |
|
| 369 |
), |
| 370 |
supports_check_mode=True) |
| 371 |
|
| 372 |
try: |
| 373 |
with iDRACConnection(module.params) as idrac: |
| 374 |
status = run_idrac_services_config(idrac, module) |
| 375 |
if status.get('Status') == "Success": |
| 376 |
changed = True |
| 377 |
msg = "Successfully configured the iDRAC services settings." |
| 378 |
if status.get('Message') and (status.get('Message') == "No changes found to commit!" or |
| 379 |
"No changes were applied" in status.get('Message')): |
| 380 |
msg = status.get('Message') |
| 381 |
changed = False |
| 382 |
module.exit_json(msg=msg, service_status=status, changed=changed) |
| 383 |
else: |
| 384 |
module.fail_json(msg="Failed to configure the iDRAC services.") |
| 385 |
except HTTPError as err: |
| 386 |
module.fail_json(msg=str(err), error_info=json.load(err)) |
| 387 |
except URLError as err: |
| 388 |
module.exit_json(msg=str(err), unreachable=True) |
| 389 |
except (RuntimeError, ImportError, SSLValidationError, IOError, ValueError, TypeError, ConnectionError) as e: |
| 390 |
module.fail_json(msg=str(e)) |
| 391 |
|
| 392 |
|
| 393 |
if __name__ == '__main__': |
| 394 |
main() |