Skip to content

Commit b4b21a8

Browse files
resolving PR comments
1 parent 6d8f492 commit b4b21a8

File tree

5 files changed

+89
-63
lines changed

5 files changed

+89
-63
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
minor_changes:
2-
- playbook_upgrade_validator - Adding a role that automatically scans the playbooks in the directory and advises of migration actions.
2+
- playbook_upgrade_validator - Adding a role that automatically scans the playbooks in the directory and advises of migration actions from v1.x.x to v2.0.0.
33
(https://github.com/ansible-collections/ibm_zos_core/pull/2399)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# ibm.ibm_zos_core.playbook_upgrade_validator
22

3-
This role validates playbooks against ibm_zos_core 2.0 and provides migration actions.
3+
This role validates playbooks against ibm_zos_core 2.0.0 and provides migration actions.
44

55
## Role Variables
66

7-
The only variable required is:
7+
The following variables are required:
88

9-
- `playbook_path`: The path to the directory containing one or more Ansible playbooks.
10-
- `output_path`: File path where validation results should be written in JSON format.
9+
- `playbook_path`: Path to the directory containing the Ansible playbooks to be validated.
10+
- `output_path`: Path to the output JSON file where results should be saved.
1111
- `ignore_response_params`: Indicates whether information about response parameter changes should be included.

roles/playbook_upgrade_validator/docs/doc_playbook_upgrade_validator

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) IBM Corporation 2023, 2025
1+
# Copyright (c) IBM Corporation 2025
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -12,13 +12,13 @@
1212
DOCUMENTATION = r'''
1313
---
1414
module: playbook_upgrade_validator
15-
version_added: "1.0.0"
15+
version_added: "2.0.0"
1616
author:
1717
- "Ravella Surendra Babu (@surendrababuravella)"
18-
short_description: Validates playbooks against ibm_zos_core 2.0 and provides migration actions.
18+
short_description: Validates playbooks against ibm_zos_core 2.0.0 and provides migration actions.
1919
description:
2020
- Scans one or more Ansible playbooks to identify deprecated or renamed parameters
21-
based on migration rules for IBM z/OS core collection version 2.0.
21+
based on migration rules for IBM z/OS Core collection version 2.0.0.
2222
- Provides line numbers, affected modules, and suggested corrective actions.
2323
options:
2424
ignore_response_params:
@@ -29,26 +29,26 @@ options:
2929
migration_map:
3030
description:
3131
- A structured set of migration rules that specifies deprecated, renamed, and modified parameters
32-
to help upgrade playbooks from ibm_zos_core 1.x to 2.0.
32+
to help upgrade playbooks from ibm_zos_core 1.x.x to 2.0.0.
3333
required: true
3434
type: dict
3535
output_path:
3636
description:
37-
- File path where validation results should be written in JSON format.
37+
- Path to the output JSON file where results should be saved.
3838
required: true
3939
type: str
4040
playbook_path:
4141
description:
42-
- The path to the directory containing one or more Ansible playbooks.
42+
- Path to the directory containing the Ansible playbooks to be validated.
4343
required: true
4444
type: str
4545
notes:
46-
- Designed to assist migration of playbooks from older IBM z/OS core collection versions to 2.0.
46+
- Designed to assist migration of playbooks from older IBM z/OS core collection versions to 2.0.0.
4747
- Supports reading tasks, blocks, and nested includes.
4848
'''
4949

5050
EXAMPLES = r'''
51-
- name: execute playbook_upgrade_validator role
51+
- name: execute playbook_upgrade_validator role to list migration changes
5252
include_role:
5353
name: ibm.ibm_zos_core.playbook_upgrade_validator
5454
vars:
@@ -60,15 +60,15 @@ EXAMPLES = r'''
6060
RETURN = r'''
6161
changed:
6262
description:
63-
- Always false as there is no state changes happen in this process.
63+
- Always false as there are no state changes happening in this process.
6464
returned: always
6565
type: bool
6666
output_path:
67-
description: File path where validation results should be written in JSON format.
67+
description: Path to the output JSON file containing validation results.
6868
returned: always
6969
type: str
7070
playbook_path:
71-
description: The path to the directory containing one or more Ansible playbooks.
71+
description: The path to the directory containing the Ansible playbooks to be validated.
7272
returned: always
7373
type: str
7474
results:

plugins/modules/playbook_upgrade_validator.py renamed to roles/playbook_upgrade_validator/files/playbook_upgrade_validator.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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
@@ -17,13 +16,13 @@
1716
DOCUMENTATION = r'''
1817
---
1918
module: playbook_upgrade_validator
20-
version_added: "1.0.0"
19+
version_added: "2.0.0"
2120
author:
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.
2423
description:
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.
2827
options:
2928
ignore_response_params:
@@ -34,26 +33,26 @@
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
5049
notes:
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

5554
EXAMPLES = 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:
@@ -65,15 +64,15 @@
6564
RETURN = r'''
6665
changed:
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
7170
output_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
7574
playbook_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
7978
results:
@@ -97,9 +96,10 @@
9796
]
9897
'''
9998

100-
from ansible.module_utils.basic import AnsibleModule
10199
import os
100+
import argparse
102101
import json
102+
import sys
103103

104104

105105
def load_playbook(path):
@@ -250,20 +250,18 @@ def validate_tasks(playbook_path, migration_map, ignore_response_params):
250250

251251

252252
def 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

284292
if __name__ == "__main__":
Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
11
---
2-
- name: Ensure ruamel.yaml is installed
2+
- name: Check if ruamel.yaml is already installed
3+
ansible.builtin.command: python3 -m pip show ruamel.yaml
4+
register: ruamel_check
5+
failed_when: false
6+
changed_when: false
7+
delegate_to: localhost
8+
9+
- name: Ensure ruamel.yaml is installed (for YAML parsing and playbook validation)
310
ansible.builtin.pip:
411
name: ruamel.yaml
512
state: present
13+
when: ruamel_check.rc != 0
14+
register: ruamel_install
615
delegate_to: localhost
716

8-
- name: Load JSON file
9-
set_fact:
10-
data: "{{ lookup('file', 'dependency_config.json') | from_json }}"
17+
- name: Check Python path
18+
ansible.builtin.command: which python3
1119
delegate_to: localhost
20+
register: python_path_result
1221

13-
- name: print Description
14-
debug:
15-
msg: "{{ playbook_path }}"
22+
- name: Load migration changes from JSON file
23+
set_fact:
24+
data: "{{ lookup('file', 'dependency_config.json') | from_json }}"
1625
delegate_to: localhost
1726

18-
- name: Run my custom module
19-
ibm.ibm_zos_core.playbook_upgrade_validator:
20-
migration_map: "{{ data }}"
21-
playbook_path: "{{ playbook_path }}"
22-
output_path: "{{ output_path }}"
23-
ignore_response_params: "{{ ignore_response_params }}"
27+
- name: Run playbook upgrade validator to list migration changes
28+
ansible.builtin.command:
29+
cmd: >
30+
"{{ python_path_result.stdout }}" "{{ role_path }}/files/playbook_upgrade_validator.py"
31+
--playbook_path "{{ playbook_path }}"
32+
--output_path "{{ output_path }}"
33+
--ignore_response_params "{{ ignore_response_params }}"
34+
--migration_map '{{ data | to_json }}'
2435
register: result
2536
delegate_to: localhost
2637

27-
- name: print debug data
38+
- name: Print path where validation results are stored
2839
debug:
29-
msg: "{{ result }}"
40+
msg: "Results saved to file: {{ output_path }}"
41+
delegate_to: localhost
42+
43+
- name: Remove ruamel.yaml if installed by this role
44+
ansible.builtin.pip:
45+
name: ruamel.yaml
46+
state: absent
47+
when: ruamel_install is defined and ruamel_install.changed
3048
delegate_to: localhost

0 commit comments

Comments
 (0)