1- #!/usr/bin/python
21# -*- coding: utf-8 -*-
32
4- # Copyright (c) IBM Corporation 2023, 2025
3+ # Copyright (c) IBM Corporation 2025
54# Licensed under the Apache License, Version 2.0 (the "License");
65# you may not use this file except in compliance with the License.
76# You may obtain a copy of the License at
1716DOCUMENTATION = r'''
1817---
1918module: playbook_upgrade_validator
20- version_added: "1 .0.0"
19+ version_added: "2 .0.0"
2120author:
2221 - "Ravella Surendra Babu (@surendrababuravella)"
23- short_description: Validates playbooks against ibm_zos_core 2.0 and provides migration actions.
22+ short_description: Validates playbooks against ibm_zos_core 2.0.0 and provides migration actions.
2423description:
2524 - Scans one or more Ansible playbooks to identify deprecated or renamed parameters
26- based on migration rules for IBM z/OS core collection version 2.0.
25+ based on migration rules for IBM z/OS Core collection version 2.0 .0.
2726 - Provides line numbers, affected modules, and suggested corrective actions.
2827options:
2928 ignore_response_params:
3433 migration_map:
3534 description:
3635 - A structured set of migration rules that specifies deprecated, renamed, and modified parameters
37- to help upgrade playbooks from ibm_zos_core 1.x to 2.0.
36+ to help upgrade playbooks from ibm_zos_core 1.x.x to 2.0 .0.
3837 required: true
3938 type: dict
4039 output_path:
4140 description:
42- - File path where validation results should be written in JSON format .
41+ - Path to the output JSON file where results should be saved .
4342 required: true
4443 type: str
4544 playbook_path:
4645 description:
47- - The path to the directory containing one or more Ansible playbooks.
46+ - Path to the directory containing the Ansible playbooks to be validated .
4847 required: true
4948 type: str
5049notes:
51- - Designed to assist migration of playbooks from older IBM z/OS core collection versions to 2.0.
50+ - Designed to assist migration of playbooks from older IBM z/OS core collection versions to 2.0.0.
5251 - Supports reading tasks, blocks, and nested includes.
5352'''
5453
5554EXAMPLES = r'''
56- - name: execute playbook_upgrade_validator role
55+ - name: execute playbook_upgrade_validator role to list migration changes
5756 include_role:
5857 name: ibm.ibm_zos_core.playbook_upgrade_validator
5958 vars:
6564RETURN = r'''
6665changed:
6766 description:
68- - Always false as there is no state changes happen in this process.
67+ - Always false as there are no state changes happening in this process.
6968 returned: always
7069 type: bool
7170output_path:
72- description: File path where validation results should be written in JSON format .
71+ description: Path to the output JSON file containing validation results .
7372 returned: always
7473 type: str
7574playbook_path:
76- description: The path to the directory containing one or more Ansible playbooks.
75+ description: The path to the directory containing the Ansible playbooks to be validated .
7776 returned: always
7877 type: str
7978results:
9796 ]
9897'''
9998
100- from ansible .module_utils .basic import AnsibleModule
10199import os
100+ import argparse
102101import json
102+ import sys
103103
104104
105105def load_playbook (path ):
@@ -250,20 +250,18 @@ def validate_tasks(playbook_path, migration_map, ignore_response_params):
250250
251251
252252def main ():
253- module = AnsibleModule (
254- argument_spec = dict (
255- playbook_path = dict (type = "str" , required = True ),
256- migration_map = dict (type = "dict" , required = True ),
257- output_path = dict (type = "str" , required = True ),
258- ignore_response_params = dict (type = "bool" , default = False )
259- ),
260- supports_check_mode = True
261- )
262-
263- playbook_path = module .params ["playbook_path" ]
264- migration_map = module .params ["migration_map" ]
265- output_path = module .params ["output_path" ]
266- ignore_response_params = module .params ["ignore_response_params" ]
253+ parser = argparse .ArgumentParser (description = "Sample Python script for z/OS Ansible role" )
254+ parser .add_argument ("--playbook_path" , type = str , required = True )
255+ parser .add_argument ("--migration_map" , type = json .loads , required = True )
256+ parser .add_argument ("--output_path" , type = str , required = True )
257+ parser .add_argument ("--ignore_response_params" , type = bool , default = False )
258+
259+ args = parser .parse_args ()
260+
261+ playbook_path = args .playbook_path
262+ migration_map = args .migration_map
263+ output_path = args .output_path
264+ ignore_response_params = args .ignore_response_params
267265 all_results = []
268266 for root , dirs , files in os .walk (playbook_path ):
269267 for file in files :
@@ -276,9 +274,19 @@ def main():
276274 with open (output_path , 'w' ) as out :
277275 json .dump (all_results , out , indent = 2 )
278276 except Exception as e :
279- module .fail_json (msg = f"Failed to write output into file: { str (e )} " )
280-
281- module .exit_json (changed = False , playbook_path = playbook_path , output_path = output_path , results = all_results )
277+ print (json .dumps ({
278+ "failed" : True ,
279+ "msg" : f"Failed to write output to file: { str (e )} "
280+ }), file = sys .stderr )
281+ sys .exit (1 )
282+
283+ result = {
284+ "playbook_path" : playbook_path ,
285+ "output_path" : output_path ,
286+ "results" : all_results
287+ }
288+ print (json .dumps (result ))
289+ sys .exit (0 )
282290
283291
284292if __name__ == "__main__" :
0 commit comments