need help for XML to JSON Parsing Error with Ansible using Parse_xml

hi ,

I was trying to parse a XML response to JSON using parse_xml from an AWS VPN output, but I’m getting the below error.
I am able to parse data with “vpn_conn_facts.vpn_connections[0].customer_gateway_configuration” but, it is when I apply the filter parse_xml, that the error arise.

→ Error:
fatal: [localhost]: FAILED! => {“msg”: “Unexpected templating type error occurred on ({{ vpn_conn_facts.vpn_connections[0].customer_gateway_configuration | parse_xml(‘aws_vpn_parser.yaml’) }}): ‘NoneType’ object is not subscriptable”}

→ playbook:

anyone here to help me out with this please ? thanks…

Perhaps, if you provide a clean piece of xml.

i’m getting below error

fatal: [localhost]: FAILED! => {“msg”: “unable to locate parse_xml template: spec”}

here is the xml data :

<?xml version="1.0" encoding="UTF-8"?>

<vpn_connection id=“vpn-008611c2097786810”>
<customer_gateway_id>cgw-0d4ee490353c847a6</customer_gateway_id>
<vpn_gateway_id>vgw-02843421cc2ba3987</vpn_gateway_id>
<vpn_connection_type>ipsec.1</vpn_connection_type>
<vpn_connection_attributes>NoBGPVPNConnection</vpn_connection_attributes>
<ipsec_tunnel>
<customer_gateway>
<tunnel_outside_address>
<ip_address>131.226.223.241</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>169.254.77.10</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</customer_gateway>
<vpn_gateway>
<tunnel_outside_address>
<ip_address>52.71.191.154</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>169.254.77.9</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</vpn_gateway>

<authentication_protocol>sha1</authentication_protocol>
<encryption_protocol>aes-128-cbc</encryption_protocol>
28800
<perfect_forward_secrecy>group2</perfect_forward_secrecy>
main
<pre_shared_key>1i5R5wqKDUx2HGvlTAIcbupHPpyns.4H</pre_shared_key>


esp
<authentication_protocol>hmac-sha1-96</authentication_protocol>
<encryption_protocol>aes-128-cbc</encryption_protocol>
3600
<perfect_forward_secrecy>group2</perfect_forward_secrecy>
tunnel
<clear_df_bit>true</clear_df_bit>
<fragmentation_before_encryption>true</fragmentation_before_encryption>
<tcp_mss_adjustment>1379</tcp_mss_adjustment>
<dead_peer_detection>
10
3
</dead_peer_detection>

</ipsec_tunnel>
<ipsec_tunnel>
<customer_gateway>
<tunnel_outside_address>
<ip_address>131.226.223.241</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>169.254.64.30</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</customer_gateway>
<vpn_gateway>
<tunnel_outside_address>
<ip_address>54.88.91.92</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>169.254.64.29</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</vpn_gateway>

<authentication_protocol>sha1</authentication_protocol>
<encryption_protocol>aes-128-cbc</encryption_protocol>
28800
<perfect_forward_secrecy>group2</perfect_forward_secrecy>
main
<pre_shared_key>NH_yZv8oTv2FkCVS5OKbydIkMEItKWOO</pre_shared_key>


esp
<authentication_protocol>hmac-sha1-96</authentication_protocol>
<encryption_protocol>aes-128-cbc</encryption_protocol>
3600
<perfect_forward_secrecy>group2</perfect_forward_secrecy>
tunnel
<clear_df_bit>true</clear_df_bit>
<fragmentation_before_encryption>true</fragmentation_before_encryption>
<tcp_mss_adjustment>1379</tcp_mss_adjustment>
<dead_peer_detection>
10
3
</dead_peer_detection>

</ipsec_tunnel>
</vpn_connection>