| 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 = r''' |
| 18 |
--- |
| 19 |
module: ome_application_network_webserver |
| 20 |
short_description: Updates the Web server configuration on OpenManage Enterprise |
| 21 |
version_added: "2.1.0" |
| 22 |
description: This module allows to configure a network web server on OpenManage Enterprise. |
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.openmanage.ome_auth_options |
| 25 |
options: |
| 26 |
webserver_port: |
| 27 |
description: |
| 28 |
- Port number used by OpenManage Enterprise to establish a secure server connection. |
| 29 |
- "I(WARNING) A change in port number results in a loss of connectivity in the current session |
| 30 |
for more than a minute." |
| 31 |
type: int |
| 32 |
webserver_timeout: |
| 33 |
description: |
| 34 |
- The duration in minutes after which a web user interface session is automatically disconnected. |
| 35 |
- If a change is made to the session timeout, it will only take effect after the next log in. |
| 36 |
type: int |
| 37 |
requirements: |
| 38 |
- "python >= 3.9.6" |
| 39 |
author: |
| 40 |
- "Jagadeesh N V(@jagadeeshnv)" |
| 41 |
- "Mangirish Kenkare(@MangirishK)" |
| 42 |
notes: |
| 43 |
- Run this module from a system that has direct access to Dell OpenManage Enterprise. |
| 44 |
- This module supports C(check_mode). |
| 45 |
''' |
| 46 |
|
| 47 |
EXAMPLES = r''' |
| 48 |
--- |
| 49 |
- name: Update web server port and session time out |
| 50 |
dellemc.openmanage.ome_application_network_webserver: |
| 51 |
hostname: "192.168.0.1" |
| 52 |
username: "username" |
| 53 |
password: "password" |
| 54 |
ca_path: "/path/to/ca_cert.pem" |
| 55 |
webserver_port: 9443 |
| 56 |
webserver_timeout: 20 |
| 57 |
|
| 58 |
- name: Update session time out |
| 59 |
dellemc.openmanage.ome_application_network_webserver: |
| 60 |
hostname: "192.168.0.1" |
| 61 |
username: "username" |
| 62 |
password: "password" |
| 63 |
ca_path: "/path/to/ca_cert.pem" |
| 64 |
webserver_timeout: 30 |
| 65 |
|
| 66 |
- name: Update web server port |
| 67 |
dellemc.openmanage.ome_application_network_webserver: |
| 68 |
hostname: "192.168.0.1" |
| 69 |
username: "username" |
| 70 |
password: "password" |
| 71 |
ca_path: "/path/to/ca_cert.pem" |
| 72 |
webserver_port: 8443 |
| 73 |
''' |
| 74 |
|
| 75 |
RETURN = r''' |
| 76 |
--- |
| 77 |
msg: |
| 78 |
type: str |
| 79 |
description: Overall status of the network web server configuration change. |
| 80 |
returned: always |
| 81 |
sample: "Successfully updated network web server configuration." |
| 82 |
webserver_configuration: |
| 83 |
type: dict |
| 84 |
description: Updated application network web server configuration. |
| 85 |
returned: success |
| 86 |
sample: { |
| 87 |
"TimeOut": 20, |
| 88 |
"PortNumber": 443, |
| 89 |
"EnableWebServer": true |
| 90 |
} |
| 91 |
error_info: |
| 92 |
description: Details of the HTTP error. |
| 93 |
returned: on HTTP error |
| 94 |
type: dict |
| 95 |
sample: { |
| 96 |
"error": { |
| 97 |
"@Message.ExtendedInfo": [ |
| 98 |
{ |
| 99 |
"Message": "Unable to complete the request because the input value |
| 100 |
for PortNumber is missing or an invalid value is entered.", |
| 101 |
"MessageArgs": [ |
| 102 |
"PortNumber" |
| 103 |
], |
| 104 |
"MessageId": "CGEN6002", |
| 105 |
"RelatedProperties": [], |
| 106 |
"Resolution": "Enter a valid value and retry the operation.", |
| 107 |
"Severity": "Critical" |
| 108 |
} |
| 109 |
], |
| 110 |
"code": "Base.1.0.GeneralError", |
| 111 |
"message": "A general error has occurred. See ExtendedInfo for more information." |
| 112 |
} |
| 113 |
} |
| 114 |
''' |
| 115 |
|
| 116 |
import json |
| 117 |
from ssl import SSLError |
| 118 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule |
| 119 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 120 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 121 |
|
| 122 |
WEBSERVER_CONFIG = "ApplicationService/Network/WebServerConfiguration" |
| 123 |
|
| 124 |
|
| 125 |
def get_updated_payload(rest_obj, module): |
| 126 |
params = module.params |
| 127 |
resp = rest_obj.invoke_request("GET", WEBSERVER_CONFIG) |
| 128 |
current_setting = resp.json_data |
| 129 |
port_changed = 0 |
| 130 |
|
| 131 |
cp = current_setting.copy() |
| 132 |
klist = cp.keys() |
| 133 |
for k in klist: |
| 134 |
if str(k).lower().startswith('@odata'): |
| 135 |
current_setting.pop(k) |
| 136 |
diff = 0 |
| 137 |
webserver_payload_map = { |
| 138 |
"webserver_port": "PortNumber", |
| 139 |
"webserver_timeout": "TimeOut", |
| 140 |
} |
| 141 |
for config, pload in webserver_payload_map.items(): |
| 142 |
pval = params.get(config) |
| 143 |
if pval is not None: |
| 144 |
if current_setting.get(pload) != pval: |
| 145 |
current_setting[pload] = pval |
| 146 |
if pload == "PortNumber": |
| 147 |
port_changed = pval |
| 148 |
diff += 1 |
| 149 |
if diff == 0: |
| 150 |
if module.check_mode: |
| 151 |
module.exit_json(msg="No changes found to be applied to the web server.") |
| 152 |
module.exit_json( |
| 153 |
msg="No changes made to the web server configuration as the entered" |
| 154 |
" values are the same as the current configuration.", webserver_configuration=current_setting) |
| 155 |
if module.check_mode: |
| 156 |
module.exit_json(changed=True, msg="Changes found to be applied to the web server.") |
| 157 |
return current_setting, port_changed |
| 158 |
|
| 159 |
|
| 160 |
def main(): |
| 161 |
specs = { |
| 162 |
"webserver_port": {"required": False, "type": "int"}, |
| 163 |
"webserver_timeout": {"required": False, "type": "int"}, |
| 164 |
} |
| 165 |
|
| 166 |
module = OmeAnsibleModule( |
| 167 |
argument_spec=specs, |
| 168 |
required_one_of=[["webserver_port", "webserver_timeout"]], |
| 169 |
supports_check_mode=True |
| 170 |
) |
| 171 |
|
| 172 |
port_change = False |
| 173 |
try: |
| 174 |
with RestOME(module.params, req_session=False) as rest_obj: |
| 175 |
updated_payload, port_change = get_updated_payload(rest_obj, module) |
| 176 |
msg = "Successfully updated network web server configuration." |
| 177 |
resp = rest_obj.invoke_request("PUT", WEBSERVER_CONFIG, data=updated_payload) |
| 178 |
module.exit_json(msg=msg, webserver_configuration=resp.json_data, changed=True) |
| 179 |
except HTTPError as err: |
| 180 |
module.exit_json(msg=str(err), error_info=json.load(err), failed=True) |
| 181 |
except URLError as err: |
| 182 |
module.exit_json(msg=str(err), unreachable=True) |
| 183 |
except SSLError as err: |
| 184 |
if port_change: |
| 185 |
module.exit_json(msg="{0} Port has changed to {1}.".format(msg, port_change), |
| 186 |
webserver_configuration=updated_payload, changed=True) |
| 187 |
else: |
| 188 |
module.exit_json(msg=str(err), failed=True) |
| 189 |
except (IOError, ValueError, TypeError, ConnectionError, SSLValidationError, OSError) as err: |
| 190 |
module.exit_json(msg=str(err), failed=True) |
| 191 |
|
| 192 |
|
| 193 |
if __name__ == "__main__": |
| 194 |
main() |