Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/idrac_timezone_ntp.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 7.1.0
7 # Copyright (C) 2018-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
8
9 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
10 #
11
12
13 from __future__ import (absolute_import, division, print_function)
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: idrac_timezone_ntp
19 short_description: Configures time zone and NTP on iDRAC
20 version_added: "2.1.0"
21 deprecated:
22 removed_at_date: "2024-12-31"
23 why: Replaced with M(dellemc.openmanage.idrac_attributes).
24 alternative: Use M(dellemc.openmanage.idrac_attributes) instead.
25 removed_from_collection: dellemc.openmanage
26 description:
27 - This module allows to configure time zone and NTP on iDRAC.
28 extends_documentation_fragment:
29 - dellemc.openmanage.idrac_auth_options
30 options:
31 setup_idrac_timezone:
32 type: str
33 description: Allows to configure time zone on iDRAC.
34 enable_ntp:
35 type: str
36 description: Allows to enable or disable NTP on iDRAC.
37 choices: [Enabled, Disabled]
38 ntp_server_1:
39 type: str
40 description: The IP address of the NTP server 1.
41 ntp_server_2:
42 type: str
43 description: The IP address of the NTP server 2.
44 ntp_server_3:
45 type: str
46 description: The IP address of the NTP server 3.
47 share_name:
48 type: str
49 description:
50 - (deprecated)Network share or a local path.
51 - This option is deprecated and will be removed in the later version.
52 share_user:
53 type: str
54 description:
55 - (deprecated)Network share user name. Use the format 'user@domain' or 'domain\\user' if user is part of a domain.
56 This option is mandatory for CIFS share.
57 - This option is deprecated and will be removed in the later version.
58 share_password:
59 type: str
60 description:
61 - (deprecated)Network share user password. This option is mandatory for CIFS share.
62 - This option is deprecated and will be removed in the later version.
63 aliases: ['share_pwd']
64 share_mnt:
65 type: str
66 description:
67 - (deprecated)Local mount path of the network share with read-write permission for ansible user.
68 This option is mandatory for network shares.
69 - This option is deprecated and will be removed in the later version.
70
71 requirements:
72 - "omsdk >= 1.2.488"
73 - "python >= 3.9.6"
74 author:
75 - "Felix Stephen (@felixs88)"
76 - "Anooja Vardhineni (@anooja-vardhineni)"
77 notes:
78 - This module requires 'Administrator' privilege for I(idrac_user).
79 - Run this module from a system that has direct access to Dell iDRAC.
80 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
81 - This module supports C(check_mode).
82 """
83
84 EXAMPLES = """
85 ---
86 - name: Configure time zone and NTP on iDRAC
87 dellemc.openmanage.idrac_timezone_ntp:
88 idrac_ip: "190.168.0.1"
89 idrac_user: "user_name"
90 idrac_password: "user_password"
91 ca_path: "/path/to/ca_cert.pem"
92 setup_idrac_timezone: "UTC"
93 enable_ntp: Enabled
94 ntp_server_1: "190.168.0.1"
95 ntp_server_2: "190.168.0.2"
96 ntp_server_3: "190.168.0.3"
97 """
98
99 RETURN = r'''
100 ---
101 msg:
102 description: Overall status of the timezone and ntp configuration.
103 returned: always
104 type: str
105 sample: "Successfully configured the iDRAC time settings."
106 timezone_ntp_status:
107 description: Job details of the time zone setting operation.
108 returned: success
109 type: dict
110 sample: {
111 "@odata.context": "/redfish/v1/$metadata#DellJob.DellJob",
112 "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/JID_861801613971",
113 "@odata.type": "#DellJob.v1_0_0.DellJob",
114 "CompletionTime": "2020-04-06T19:06:01",
115 "Description": "Job Instance",
116 "EndTime": null,
117 "Id": "JID_861801613971",
118 "JobState": "Completed",
119 "JobType": "ImportConfiguration",
120 "Message": "Successfully imported and applied Server Configuration Profile.",
121 "MessageArgs": [],
122 "MessageId": "SYS053",
123 "Name": "Import Configuration",
124 "PercentComplete": 100,
125 "StartTime": "TIME_NOW",
126 "Status": "Success",
127 "TargetSettingsURI": null,
128 "retval": true
129 }
130 error_info:
131 description: Details of the HTTP Error.
132 returned: on HTTP error
133 type: dict
134 sample: {
135 "error": {
136 "code": "Base.1.0.GeneralError",
137 "message": "A general error has occurred. See ExtendedInfo for more information.",
138 "@Message.ExtendedInfo": [
139 {
140 "MessageId": "GEN1234",
141 "RelatedProperties": [],
142 "Message": "Unable to process the request because an error occurred.",
143 "MessageArgs": [],
144 "Severity": "Critical",
145 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
146 }
147 ]
148 }
149 }
150 '''
151
152 import os
153 import tempfile
154 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params
155 from ansible.module_utils.basic import AnsibleModule
156 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
157 from ansible.module_utils.urls import ConnectionError, SSLValidationError
158 import json
159 try:
160 from omdrivers.enums.iDRAC.iDRAC import NTPEnable_NTPConfigGroupTypes
161 from omsdk.sdkfile import file_share_manager
162 except ImportError:
163 pass
164
165
166 def run_idrac_timezone_config(idrac, module):
167 """
168 Get Lifecycle Controller status
169
170 Keyword arguments:
171 idrac -- iDRAC handle
172 module -- Ansible module
173 """
174 idrac.use_redfish = True
175 share_path = tempfile.gettempdir() + os.sep
176 upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True)
177 if not upd_share.IsValid:
178 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
179 "share mount, and share credentials provided are correct.")
180 idrac.config_mgr.set_liason_share(upd_share)
181
182 if module.params['setup_idrac_timezone'] is not None:
183 idrac.config_mgr.configure_timezone(module.params['setup_idrac_timezone'])
184
185 if module.params['enable_ntp'] is not None:
186 idrac.config_mgr.configure_ntp(
187 enable_ntp=NTPEnable_NTPConfigGroupTypes[module.params['enable_ntp']]
188 )
189 if module.params['ntp_server_1'] is not None:
190 idrac.config_mgr.configure_ntp(
191 ntp_server_1=module.params['ntp_server_1']
192 )
193 if module.params['ntp_server_2'] is not None:
194 idrac.config_mgr.configure_ntp(
195 ntp_server_2=module.params['ntp_server_2']
196 )
197 if module.params['ntp_server_3'] is not None:
198 idrac.config_mgr.configure_ntp(
199 ntp_server_3=module.params['ntp_server_3']
200 )
201
202 if module.check_mode:
203 msg = idrac.config_mgr.is_change_applicable()
204 else:
205 msg = idrac.config_mgr.apply_changes(reboot=False)
206 return msg
207
208
209 # Main
210 def main():
211 specs = {
212 # Export Destination
213 "share_name": {"required": False, "type": 'str'},
214 "share_password": {"required": False, "type": 'str', "aliases": ['share_pwd'], "no_log": True},
215 "share_user": {"required": False, "type": 'str'},
216 "share_mnt": {"required": False, "type": 'str'},
217
218 # setup NTP
219 "enable_ntp": {"required": False, "choices": ['Enabled', 'Disabled']},
220 "ntp_server_1": {"required": False},
221 "ntp_server_2": {"required": False},
222 "ntp_server_3": {"required": False},
223
224 # set up timezone
225 "setup_idrac_timezone": {"required": False, "type": 'str'},
226
227 }
228 specs.update(idrac_auth_params)
229 module = AnsibleModule(
230 argument_spec=specs,
231 supports_check_mode=True)
232
233 try:
234 with iDRACConnection(module.params) as idrac:
235 changed = False
236 msg = run_idrac_timezone_config(idrac, module)
237 if "Status" in msg:
238 if msg['Status'] == "Success":
239 changed = True
240 if "Message" in msg:
241 if msg['Message'] == "No changes found to commit!":
242 changed = False
243 except HTTPError as err:
244 module.fail_json(msg=str(err), error_info=json.load(err))
245 except URLError as err:
246 module.exit_json(msg=str(err), unreachable=True)
247 except AttributeError as err:
248 if "NoneType" in str(err):
249 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
250 "share mount, and share credentials provided are correct.")
251 except (RuntimeError, SSLValidationError, ConnectionError, KeyError,
252 ImportError, ValueError, TypeError) as e:
253 module.fail_json(msg=str(e))
254 module.exit_json(msg="Successfully configured the iDRAC time settings.",
255 timezone_ntp_status=msg, changed=changed)
256
257
258 if __name__ == '__main__':
259 main()