Skip to content

Commit cf53a90

Browse files
author
Shiva Shankar Vaddepally
committed
supported only tasks variation
Signed-off-by: Shiva Shankar Vaddepally <shivashankar.vaddepally@cloud.com>
1 parent ebc8c60 commit cf53a90

3 files changed

Lines changed: 51 additions & 53 deletions

File tree

migrationtool/README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
# NetScaler ADC Ansible Collection Migration Tool
22

3-
Migrates Ansible playbooks from legacy `citrix.adc` collection to new `netscaler.adc` collection format.
3+
This tool helps migrate existing Ansible playbooks from the legacy `citrix.adc` collection to the new `netscaler.adc` collection format.
44

5-
## Usage
5+
## Overview
66

7-
```bash
8-
python3 convert_yaml.py -i input_playbook.yaml -o output_playbook.yaml
9-
```
7+
The migration tool converts YAML playbooks that use:
8+
- Legacy `citrix.adc` modules
9+
- `citrix_adc_nitro_request` generic module
1010

11-
**Arguments:**
12-
- `-i, --input`: (Required) Input YAML playbook
13-
- `-o, --output`: (Optional) Output file (defaults to `output.yaml`)
14-
- `-v, --verbose`: (Optional) Enable verbose output
11+
Into playbooks that use the new `netscaler.adc` collection modules.
1512

16-
## What it converts
13+
## Features
1714

18-
1. **Legacy modules**: `citrix.adc.lbvserver``netscaler.adc.lbvserver`
19-
2. **NITRO requests**: `citrix_adc_nitro_request` → specific resource modules
15+
- **Module Mapping**: Automatically maps legacy module names to new collection modules
16+
- **State Conversion**: Converts NITRO request operations to appropriate state values
17+
- **Credential Handling**: Preserves and converts authentication parameters
18+
- **YAML Structure Preservation**: Maintains playbook structure, variables, and task organization
2019

21-
### Example Conversion
20+
## Usage
2221

23-
**Before:**
24-
```yaml
25-
- name: Configure LB vserver
26-
citrix_adc_nitro_request:
27-
operation: present
28-
resource: lbvserver
29-
name: my_lb_vserver
30-
attributes:
31-
servicetype: HTTP
32-
port: 80
33-
```
22+
### Basic Usage
3423

35-
**After:**
36-
```yaml
37-
- name: Configure LB vserver
38-
netscaler.adc.lbvserver:
39-
state: present
40-
name: my_lb_vserver
41-
servicetype: HTTP
42-
port: 80
24+
```bash
25+
python3 convert_yaml.py -i input_playbook.yaml -o output_playbook.yaml
4326
```
4427

45-
## Requirements
28+
### Arguments
29+
30+
- `-i, --input`: (Required) Path to the input YAML playbook
31+
- `-o, --output`: (Optional) Path for the output file. Defaults to `output.yaml`
32+
33+
### Example
4634

4735
```bash
48-
pip install pyyaml jinja2
36+
python convert_yaml.py -i legacy_playbook.yml -o migrated_playbook.yml
4937
```
5038

51-
## Files
39+
## Supported Conversions
5240

53-
- `convert_yaml.py`: Main conversion script
54-
- `resourcelist.py`: Module and state mappings
41+
### Legacy Module Mappings
42+
The tool uses `resource_map` to convert legacy module names to new collection modules:
43+
- `citrix.adc.lbvserver``netscaler.adc.lbvserver`
44+
- `lbvserver``netscaler.adc.lbvserver`
45+
46+
### NITRO Request Conversion
47+
Converts `citrix_adc_nitro_request` tasks to specific resource modules:
48+
49+
**Before:**
50+
```yaml
51+
- name: Configure LB vserver
52+
citrix_adc_nitro_request:
53+
nsip: "{{ nsip }}"
54+
nitro_user: "{{ nitro_user }}"
5555
nitro_pass: "{{ nitro_pass }}"
5656
operation: present
5757
resource: lbvserver

migrationtool/convert_yaml.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ def convert_yaml_file(input_file, output_file, template_file, verbose):
3939
# Convert input file (citrix.adc) to output file (citrix.adc.yaml) using template
4040
with open(input_file, 'r') as infile:
4141
data = yaml.safe_load(infile)
42-
42+
task_only = False
4343
# Handle both list and dict formats
4444
if isinstance(data, list):
4545
# If data is a list, assume it's a list of plays/tasks
46-
if len(data) > 0 and isinstance(data[0], dict):
46+
if len(data) == 1 and isinstance(data[0], dict):
4747
# Take the first item if it's a dictionary
4848
play_data = data[0]
4949
else:
5050
# If it's a list of tasks, wrap it in a play structure
51+
task_only = True
5152
play_data = {"tasks": data}
5253
elif isinstance(data, dict):
5354
play_data = data
@@ -124,16 +125,20 @@ def convert_yaml_file(input_file, output_file, template_file, verbose):
124125
new_tasks.append(new_task)
125126

126127
# Playbook struct
127-
playbook = [{
128-
"name": name,
129-
"hosts": hosts,
130-
"gather_facts": gather_facts,
131-
"vars": vars_data,
132-
"tasks": new_tasks
133-
}]
128+
if task_only:
129+
playbook = new_tasks
130+
else:
131+
playbook = [{
132+
"name": name,
133+
"hosts": hosts,
134+
"gather_facts": gather_facts,
135+
"vars": vars_data,
136+
"tasks": new_tasks
137+
}]
134138

135139
# Write the playbook directly as YAML without template
136140
with open(output_file, 'w') as outfile:
141+
outfile.write("---\n")
137142
yaml.dump(playbook, outfile, default_flow_style=False, sort_keys=False, Dumper=CustomDumper, indent=2)
138143

139144
print(f"Output written to: {output_file}")

migrationtool/template.j2

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)