I'm trying to do a simple list to show all ports associated with a particular vlan and have this output to a csv.
Code works but can't figure out how can I get around removing the 'u' and the [] associated with the line 'InterfaceID' in the output. I know the array need to be converted to a string just wondering how I can do this without modifying the code too much.
Thank you in advance for any tips.
Code:
- name: parse output
set_fact:
vlan_output: "{{vlan_info.stdout[0] | parse_cli_textfsm(parse_template)}}"
- name: write lines to file
copy:
content: "{{ ['InterfaceID','VlanID','NAME'] | zip([item.INTERFACES,item.VLAN_ID,item.NAME]) | map('join', ', ') | join('\n') }}"
dest: "output.csv"
with_items: "{{vlan_output}}"
- debug:
var: vlan_output
Debug of vlan_output:
"vlan_output": [
{
"INTERFACES": [
"Gi1/0/2",
"Gi1/0/5",
"Gi1/0/7"
],
"NAME": "test",
"STATUS": "active",
"VLAN_ID": "10"
}
]
Excel Output:
InterfaceID, [u'Gi1/0/2', u'Gi1/0/5', u'Gi1/0/7']
VlanID, 10
NAME, test