| 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_system_lockdown_mode |
| 20 |
short_description: Configures system lockdown mode for iDRAC |
| 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 is allows to Enable or Disable System lockdown Mode. |
| 29 |
extends_documentation_fragment: |
| 30 |
- dellemc.openmanage.idrac_auth_options |
| 31 |
options: |
| 32 |
share_name: |
| 33 |
type: str |
| 34 |
description: |
| 35 |
- (deprecated)Network share or a local path. |
| 36 |
- This option is deprecated and will be removed in the later version. |
| 37 |
share_user: |
| 38 |
type: str |
| 39 |
description: |
| 40 |
- (deprecated)Network share user in the format 'user@domain' or 'domain\\user' if user is |
| 41 |
part of a domain else 'user'. This option is mandatory for CIFS Network Share. |
| 42 |
- This option is deprecated and will be removed in the later version. |
| 43 |
share_password: |
| 44 |
type: str |
| 45 |
description: |
| 46 |
- (deprecated)Network share user password. This option is mandatory for CIFS Network Share. |
| 47 |
- This option is deprecated and will be removed in the later version. |
| 48 |
aliases: ['share_pwd'] |
| 49 |
share_mnt: |
| 50 |
type: str |
| 51 |
description: |
| 52 |
- (deprecated)Local mount path of the network share with read-write permission for ansible user. |
| 53 |
This option is mandatory for Network Share. |
| 54 |
- This option is deprecated and will be removed in the later version. |
| 55 |
lockdown_mode: |
| 56 |
required: True |
| 57 |
type: str |
| 58 |
description: Whether to Enable or Disable system lockdown mode. |
| 59 |
choices: [Enabled, Disabled] |
| 60 |
requirements: |
| 61 |
- "omsdk >= 1.2.488" |
| 62 |
- "python >= 3.9.6" |
| 63 |
author: "Felix Stephen (@felixs88)" |
| 64 |
notes: |
| 65 |
- This module requires 'Administrator' privilege for I(idrac_user). |
| 66 |
- Run this module from a system that has direct access to Dell iDRAC. |
| 67 |
- This module supports both IPv4 and IPv6 address for I(idrac_ip). |
| 68 |
- This module does not support C(check_mode). |
| 69 |
""" |
| 70 |
|
| 71 |
EXAMPLES = """ |
| 72 |
--- |
| 73 |
- name: Check System Lockdown Mode |
| 74 |
dellemc.openmanage.dellemc_system_lockdown_mode: |
| 75 |
idrac_ip: "192.168.0.1" |
| 76 |
idrac_user: "user_name" |
| 77 |
idrac_password: "user_password" |
| 78 |
ca_path: "/path/to/ca_cert.pem" |
| 79 |
lockdown_mode: "Disabled" |
| 80 |
""" |
| 81 |
|
| 82 |
RETURN = r''' |
| 83 |
--- |
| 84 |
msg: |
| 85 |
description: "Lockdown mode of the system is configured." |
| 86 |
returned: always |
| 87 |
type: str |
| 88 |
sample: "Successfully completed the lockdown mode operations." |
| 89 |
system_lockdown_status: |
| 90 |
type: dict |
| 91 |
description: Storage configuration job and progress details from the iDRAC. |
| 92 |
returned: success |
| 93 |
sample: |
| 94 |
{ |
| 95 |
"Data": { |
| 96 |
"StatusCode": 200, |
| 97 |
"body": { |
| 98 |
"@Message.ExtendedInfo": [ |
| 99 |
{ |
| 100 |
"Message": "Successfully Completed Request", |
| 101 |
"MessageArgs": [], |
| 102 |
"[email protected]": 0, |
| 103 |
"MessageId": "Base.1.0.Success", |
| 104 |
"RelatedProperties": [], |
| 105 |
"[email protected]": 0, |
| 106 |
"Resolution": "None", |
| 107 |
"Severity": "OK" |
| 108 |
} |
| 109 |
] |
| 110 |
} |
| 111 |
}, |
| 112 |
"Message": "none", |
| 113 |
"Status": "Success", |
| 114 |
"StatusCode": 200, |
| 115 |
"retval": true |
| 116 |
} |
| 117 |
error_info: |
| 118 |
description: Details of the HTTP Error. |
| 119 |
returned: on HTTP error |
| 120 |
type: dict |
| 121 |
sample: { |
| 122 |
"error": { |
| 123 |
"code": "Base.1.0.GeneralError", |
| 124 |
"message": "A general error has occurred. See ExtendedInfo for more information.", |
| 125 |
"@Message.ExtendedInfo": [ |
| 126 |
{ |
| 127 |
"MessageId": "GEN1234", |
| 128 |
"RelatedProperties": [], |
| 129 |
"Message": "Unable to process the request because an error occurred.", |
| 130 |
"MessageArgs": [], |
| 131 |
"Severity": "Critical", |
| 132 |
"Resolution": "Retry the operation. If the issue persists, contact your system administrator." |
| 133 |
} |
| 134 |
] |
| 135 |
} |
| 136 |
} |
| 137 |
''' |
| 138 |
|
| 139 |
import os |
| 140 |
import tempfile |
| 141 |
import json |
| 142 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params |
| 143 |
from ansible.module_utils.basic import AnsibleModule |
| 144 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 145 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 146 |
try: |
| 147 |
from omsdk.sdkfile import file_share_manager |
| 148 |
except ImportError: |
| 149 |
pass |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
def run_system_lockdown_mode(idrac, module): |
| 154 |
""" |
| 155 |
Get Lifecycle Controller status |
| 156 |
|
| 157 |
Keyword arguments: |
| 158 |
idrac -- iDRAC handle |
| 159 |
module -- Ansible module |
| 160 |
""" |
| 161 |
msg = {'changed': False, 'failed': False, 'msg': "Successfully completed the lockdown mode operations."} |
| 162 |
idrac.use_redfish = True |
| 163 |
share_path = tempfile.gettempdir() + os.sep |
| 164 |
upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True) |
| 165 |
if not upd_share.IsValid: |
| 166 |
module.fail_json(msg="Unable to access the share. Ensure that the share name, " |
| 167 |
"share mount, and share credentials provided are correct.") |
| 168 |
set_liason = idrac.config_mgr.set_liason_share(upd_share) |
| 169 |
if set_liason['Status'] == "Failed": |
| 170 |
try: |
| 171 |
message = set_liason['Data']['Message'] |
| 172 |
except (IndexError, KeyError): |
| 173 |
message = set_liason['Message'] |
| 174 |
module.fail_json(msg=message) |
| 175 |
if module.params['lockdown_mode'] == 'Enabled': |
| 176 |
msg["system_lockdown_status"] = idrac.config_mgr.enable_system_lockdown() |
| 177 |
elif module.params['lockdown_mode'] == 'Disabled': |
| 178 |
msg["system_lockdown_status"] = idrac.config_mgr.disable_system_lockdown() |
| 179 |
|
| 180 |
if msg.get("system_lockdown_status") and "Status" in msg['system_lockdown_status']: |
| 181 |
if msg['system_lockdown_status']['Status'] == "Success": |
| 182 |
msg['changed'] = True |
| 183 |
else: |
| 184 |
module.fail_json(msg="Failed to complete the lockdown mode operations.") |
| 185 |
return msg |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
def main(): |
| 190 |
specs = dict( |
| 191 |
share_name=dict(required=False, type='str'), |
| 192 |
share_password=dict(required=False, type='str', |
| 193 |
aliases=['share_pwd'], no_log=True), |
| 194 |
share_user=dict(required=False, type='str'), |
| 195 |
share_mnt=dict(required=False, type='str'), |
| 196 |
lockdown_mode=dict(required=True, choices=['Enabled', 'Disabled']) |
| 197 |
) |
| 198 |
specs.update(idrac_auth_params) |
| 199 |
module = AnsibleModule( |
| 200 |
argument_spec=specs, |
| 201 |
supports_check_mode=False) |
| 202 |
|
| 203 |
try: |
| 204 |
with iDRACConnection(module.params) as idrac: |
| 205 |
msg = run_system_lockdown_mode(idrac, module) |
| 206 |
except HTTPError as err: |
| 207 |
module.fail_json(msg=str(err), error_info=json.load(err)) |
| 208 |
except URLError as err: |
| 209 |
module.exit_json(msg=str(err), unreachable=True) |
| 210 |
except (RuntimeError, ImportError, SSLValidationError, IOError, ValueError, TypeError, ConnectionError) as e: |
| 211 |
module.fail_json(msg=str(e)) |
| 212 |
module.exit_json(msg=msg["msg"], system_lockdown_status=msg["system_lockdown_status"], changed=msg["changed"]) |
| 213 |
|
| 214 |
|
| 215 |
if __name__ == '__main__': |
| 216 |
main() |