Skip to content

Commit f4793a3

Browse files
[ome_configuration_compliance_baseline] - Added support for scheduling or staging the job (#678)
* added support for scheduling or staging * added cron validation and updated message --------- Co-authored-by: Rajshekar P <31881341+rajshekarp87@users.noreply.github.com>
1 parent 3aca2ba commit f4793a3

File tree

6 files changed

+256
-11
lines changed

6 files changed

+256
-11
lines changed

docs/modules/ome_configuration_compliance_baseline.rst

+57
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ Parameters
9393
This option is applicable when \ :emphasis:`command`\ is \ :literal:`create`\ , or \ :literal:`modify`\ .
9494

9595

96+
run_later (optional, bool, None)
97+
Indicates whether to remediate immediately or in the future.
98+
99+
This is applicable when \ :emphasis:`command`\ is \ :literal:`remediate`\ .
100+
101+
If \ :emphasis:`run\_later`\ is \ :literal:`true`\ , then \ :emphasis:`staged\_at\_reboot`\ is ignored.
102+
103+
If \ :emphasis:`run\_later`\ is \ :literal:`true`\ , then \ :emphasis:`job\_wait`\ is not applicable.
104+
105+
If \ :emphasis:`run\_later`\ is \ :literal:`true`\ , then \ :emphasis:`cron`\ must be specified.
106+
107+
108+
cron (optional, str, None)
109+
Provide a cron expression based on Quartz cron format.
110+
111+
Time format is "%S %M %H %d %m ? %Y".
112+
113+
This is applicable when \ :emphasis:`run\_later`\ is \ :literal:`true`\ .
114+
115+
116+
staged_at_reboot (optional, bool, None)
117+
Indicates whether remediate has to be executed on next reboot.
118+
119+
If \ :emphasis:`staged\_at\_reboot`\ is \ :literal:`true`\ , then remediation will occur during the next reboot.
120+
121+
96122
job_wait (optional, bool, True)
97123
Provides the option to wait for job completion.
98124

@@ -271,6 +297,32 @@ Examples
271297
command: "remediate"
272298
names: "baseline1"
273299

300+
- name: Remediate specific non-compliant devices to a configuration compliance baseline using device IDs at scheduled time
301+
dellemc.openmanage.ome_configuration_compliance_baseline:
302+
hostname: "192.168.0.1"
303+
username: "username"
304+
password: "password"
305+
ca_path: "/path/to/ca_cert.pem"
306+
command: "remediate"
307+
names: "baseline1"
308+
device_ids:
309+
- 1111
310+
run_later: true
311+
cron: "0 10 11 14 02 ? 2032" # Feb 14,2032 11:10:00
312+
313+
- name: Remediate specific non-compliant devices to a configuration compliance baseline using device service tags on next reboot
314+
dellemc.openmanage.ome_configuration_compliance_baseline:
315+
hostname: "192.168.0.1"
316+
username: "username"
317+
password: "password"
318+
ca_path: "/path/to/ca_cert.pem"
319+
command: "remediate"
320+
names: "baseline1"
321+
device_service_tags:
322+
- "SVCTAG1"
323+
- "SVCTAG2"
324+
staged_at_reboot: true
325+
274326

275327

276328
Return Values
@@ -292,6 +344,10 @@ job_id (when I(command) is C(remediate), int, 14123)
292344
Task ID created when \ :emphasis:`command`\ is \ :literal:`remediate`\ .
293345

294346

347+
job_details (on job failure, list, [{'ElapsedTime': '00:22:17', 'EndTime': '2024-06-19 13:42:41.285', 'ExecutionHistoryId': 797320, 'Id': 14123, 'IdBaseEntity': 19559, 'JobStatus': {'Id': 2070, 'Name': 'Failed'}, 'Key': 'SVCTAG1', 'Progress': '100', 'StartTime': '2024-06-19 13:20:23.495', 'Value': 'Starting Pre-checks....LC status is : InUse, wait for 30 seconds and retry ...(1)'}])
348+
Details of the failed job.
349+
350+
295351
error_info (on HTTP error, dict, {'error': {'code': 'Base.1.0.GeneralError', 'message': 'A general error has occurred. See ExtendedInfo for more information.', '@Message.ExtendedInfo': [{'MessageId': 'GEN1234', 'RelatedProperties': [], 'Message': 'Unable to process the request because an error occurred.', 'MessageArgs': [], 'Severity': 'Critical', 'Resolution': 'Retry the operation. If the issue persists, contact your system administrator.'}]}})
296352
Details of the HTTP Error.
297353

@@ -311,4 +367,5 @@ Authors
311367

312368
- Sajna Shetty(@Sajna-Shetty)
313369
- Abhishek Sinha(@Abhishek-Dell)
370+
- Shivam Sharma(@ShivamSh3)
314371

playbooks/ome/compliance/ome_configuration_compliance_baseline.yml

+30
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,33 @@
121121
job_wait_timeout: 2000
122122
names: "baseline1"
123123
delegate_to: localhost
124+
125+
- name: Remediate specific non-compliant devices to a configuration
126+
compliance baseline using device IDs at scheduled time
127+
dellemc.openmanage.ome_configuration_compliance_baseline:
128+
hostname: "192.168.0.1"
129+
username: "username"
130+
password: "password"
131+
ca_path: "/path/to/ca_cert.pem"
132+
command: "remediate"
133+
names: "baseline1"
134+
device_ids:
135+
- 1111
136+
run_later: true
137+
cron: "0 00 11 14 02 ? 2032" # Feb 14,2032 4:30:00 PM
138+
delegate_to: localhost
139+
140+
- name: Remediate specific non-compliant devices to a configuration
141+
compliance baseline using device service tags on next reboot
142+
dellemc.openmanage.ome_configuration_compliance_baseline:
143+
hostname: "192.168.0.1"
144+
username: "username"
145+
password: "password"
146+
ca_path: "/path/to/ca_cert.pem"
147+
command: "remediate"
148+
names: "baseline1"
149+
device_service_tags:
150+
- "SVCTAG1"
151+
- "SVCTAG2"
152+
staged_at_reboot: true
153+
delegate_to: localhost

plugins/module_utils/ome.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
# Dell OpenManage Ansible Modules
4-
# Version 9.3.0
4+
# Version 9.4.0
55
# Copyright (C) 2019-2024 Dell Inc. or its subsidiaries. All Rights Reserved.
66

77
# Redistribution and use in source and binary forms, with or without modification,
@@ -38,6 +38,7 @@
3838
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
3939
from ansible.module_utils.six.moves.urllib.parse import urlencode
4040
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import config_ipv6
41+
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import strip_substr_dict
4142
from ansible.module_utils.basic import AnsibleModule
4243

4344
ome_auth_params = {
@@ -58,6 +59,7 @@
5859
JOB_URI = "JobService/Jobs({job_id})"
5960
JOB_SERVICE_URI = "JobService/Jobs"
6061
HOST_UNRESOLVED_MSG = "Unable to resolve hostname or IP {0}."
62+
JOB_EXEC_HISTORY = "JobService/Jobs({job_id})/ExecutionHistories"
6163

6264

6365
class OpenURLResponse(object):
@@ -406,6 +408,24 @@ def _get_omam_ca_env(self):
406408
"""Check if the value is set in REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE or OMAM_CA_BUNDLE or returns None"""
407409
return os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("CURL_CA_BUNDLE") or os.environ.get("OMAM_CA_BUNDLE")
408410

411+
def get_job_execution_details(self, job_id):
412+
try:
413+
job_detail_status = []
414+
resp = self.invoke_request('GET', JOB_EXEC_HISTORY.format(job_id=job_id))
415+
ex_hist = resp.json_data.get('value')
416+
# Sorting based on startTime and to get latest execution instance.
417+
tmp_dict = dict((x["StartTime"], x["Id"]) for x in ex_hist)
418+
sorted_dates = sorted(tmp_dict.keys())
419+
ex_url = JOB_EXEC_HISTORY.format(job_id=job_id) + "({0})/ExecutionHistoryDetails".format(tmp_dict[sorted_dates[-1]])
420+
all_exec = self.get_all_items_with_pagination(ex_url)
421+
for jb_ip in all_exec.get('value'):
422+
jb_ip = strip_substr_dict(jb_ip)
423+
jb_ip.get('JobStatus', {}).pop('@odata.type', None)
424+
job_detail_status.append(jb_ip)
425+
except Exception:
426+
pass
427+
return job_detail_status
428+
409429

410430
class OmeAnsibleModule(AnsibleModule):
411431
def __init__(self, argument_spec, bypass_checks=False, no_log=False,

0 commit comments

Comments
 (0)