Passing json data without losing the double quotes

ansible 2.5.0 (devel 1068aa3ce7) last updated 2017/11/01 11:34:22 (GMT +200)
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/home/actionmystique/Ansible/git-yang-networkop/ansible-101/library’]
ansible python module location = /home/actionmystique/src/Ansible/git-ansible/lib/ansible
executable location = /home/actionmystique/src/Ansible/git-ansible/bin/ansible
python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

I wrote a bash script to check the json dictionary returned by the uri module for duplicate keys.
For instance, Sending “GET” to “https://NX_OSv_9k_Spine_31/restconf/data/openconfig-interfaces:interfaces?content=config” returns a json string with multiple duplicate keys:

“content”: “{"interfaces":{"interface":{"config":{"name":"vlan1"},"name":"vlan1","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/39"},"name":"eth1\/39","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/48"},"name":"eth1\/48","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/42"},"name":"eth1\/42","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/37"},"name":"eth1\/37","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/35"},"name":"eth1\/35","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/27"},"name":"eth1\/27","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/3"},"name":"eth1\/3","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.112.11","prefix-length":"24"},"ip":"10.3.112.11"}}}}},"routed-vlan":{"ipv4":{"addresses":{"address":{"config":{"ip":"10.3.112.11","prefix-length":"24"},"ip":"10.3.112.11"}}}}},"interface":{"config":{"name":"eth1\/52"},"name":"eth1\/52","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/54"},"name":"eth1\/54","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/61"},"name":"eth1\/61","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/58"},"name":"eth1\/58","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/4"},"name":"eth1\/4","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.113.11","prefix-length":"24"},"ip":"10.3.113.11"}}}},"subinterface":{"index":"20"},"subinterface":{"index":"10"}}},"interface":{"config":{"name":"eth1\/29"},"name":"eth1\/29","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/47"},"name":"eth1\/47","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/14"},"name":"eth1\/14","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/9"},"name":"eth1\/9","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/7"},"name":"eth1\/7","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.116.11","prefix-length":"24"},"ip":"10.3.116.11"}}}},"subinterface":{"index":"20"},"subinterface":{"index":"10"}}},"interface":{"config":{"name":"eth1\/8"},"name":"eth1\/8","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/25"},"name":"eth1\/25","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/18"},"name":"eth1\/18","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/40"},"name":"eth1\/40","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/12"},"name":"eth1\/12","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/36"},"name":"eth1\/36","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/16"},"name":"eth1\/16","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/1"},"name":"eth1\/1","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"172.21.100.111","prefix-length":"16"},"ip":"172.21.100.111"}}}}},"routed-vlan":{"ipv4":{"addresses":{"address":{"config":{"ip":"172.21.100.111","prefix-length":"16"},"ip":"172.21.100.111"}}}}},"interface":{"config":{"name":"eth1\/10"},"name":"eth1\/10","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/49"},"name":"eth1\/49","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/31"},"name":"eth1\/31","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/53"},"name":"eth1\/53","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/19"},"name":"eth1\/19","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/38"},"name":"eth1\/38","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/56"},"name":"eth1\/56","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/43"},"name":"eth1\/43","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/44"},"name":"eth1\/44","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/5"},"name":"eth1\/5","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.114.11","prefix-length":"24"},"ip":"10.3.114.11"}}}},"subinterface":{"index":"10"},"subinterface":{"index":"20"}}},"interface":{"config":{"name":"eth1\/34"},"name":"eth1\/34","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/23"},"name":"eth1\/23","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/21"},"name":"eth1\/21","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/28"},"name":"eth1\/28","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/22"},"name":"eth1\/22","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/24"},"name":"eth1\/24","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/55"},"name":"eth1\/55","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/33"},"name":"eth1\/33","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/11"},"name":"eth1\/11","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/64"},"name":"eth1\/64","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/41"},"name":"eth1\/41","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/13"},"name":"eth1\/13","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/45"},"name":"eth1\/45","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/2"},"name":"eth1\/2","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.111.11","prefix-length":"24"},"ip":"10.3.111.11"}}}}},"routed-vlan":{"ipv4":{"addresses":{"address":{"config":{"ip":"10.3.111.11","prefix-length":"24"},"ip":"10.3.111.11"}}}}},"interface":{"config":{"name":"eth1\/63"},"name":"eth1\/63","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/60"},"name":"eth1\/60","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/62"},"name":"eth1\/62","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/17"},"name":"eth1\/17","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/59"},"name":"eth1\/59","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/46"},"name":"eth1\/46","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/50"},"name":"eth1\/50","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/20"},"name":"eth1\/20","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/57"},"name":"eth1\/57","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/6"},"name":"eth1\/6","subinterfaces":{"subinterface":{"index":"0","ipv4":{"addresses":{"address":{"config":{"ip":"10.3.115.11","prefix-length":"24"},"ip":"10.3.115.11"}}}},"subinterface":{"index":"20"},"subinterface":{"index":"10"}}},"interface":{"config":{"name":"eth1\/26"},"name":"eth1\/26","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/51"},"name":"eth1\/51","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/15"},"name":"eth1\/15","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/32"},"name":"eth1\/32","subinterfaces":{"subinterface":{"index":"0"}}},"interface":{"config":{"name":"eth1\/30"},"name":"eth1\/30","subinterfaces":{"subinterface":{"index":"0"}}},"xmlns":"http:\/\/openconfig.net\/yang\/interfaces"}}”,

If I call the script with the data as parameter, the double quotes are removed:

  • name: Checking for duplicate keys in json answer
    local_action: script /home/actionmystique/Bash/Scripts/json-check-duplicate-keys.sh “{{ uri_return.content }}”
    register: json_check_duplicate_keys
    failed_when: json_check_duplicate_keys.stderr

leads to the uri_return.content data appear within the script as:
{interfaces:{interface:{config:{name:vlan1},name:vlan1,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/39},name:eth1/39,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/48},name:eth1/48,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/42},name:eth1/42,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/37},name:eth1/37,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/35},name:eth1/35,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/27},name:eth1/27,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/3},name:eth1/3,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.112.11,prefix-length:24},ip:10.3.112.11}}}}},routed-vlan:{ipv4:{addresses:{address:{config:{ip:10.3.112.11,prefix-length:24},ip:10.3.112.11}}}}},interface:{config:{name:eth1/52},name:eth1/52,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/54},name:eth1/54,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/61},name:eth1/61,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/58},name:eth1/58,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/4},name:eth1/4,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.113.11,prefix-length:24},ip:10.3.113.11}}}},subinterface:{index:20},subinterface:{index:10}}},interface:{config:{name:eth1/29},name:eth1/29,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/47},name:eth1/47,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/14},name:eth1/14,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/9},name:eth1/9,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/7},name:eth1/7,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.116.11,prefix-length:24},ip:10.3.116.11}}}},subinterface:{index:20},subinterface:{index:10}}},interface:{config:{name:eth1/8},name:eth1/8,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/25},name:eth1/25,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/18},name:eth1/18,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/40},name:eth1/40,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/12},name:eth1/12,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/36},name:eth1/36,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/16},name:eth1/16,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/1},name:eth1/1,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:172.21.100.111,prefix-length:16},ip:172.21.100.111}}}}},routed-vlan:{ipv4:{addresses:{address:{config:{ip:172.21.100.111,prefix-length:16},ip:172.21.100.111}}}}},interface:{config:{name:eth1/10},name:eth1/10,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/49},name:eth1/49,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/31},name:eth1/31,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/53},name:eth1/53,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/19},name:eth1/19,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/38},name:eth1/38,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/56},name:eth1/56,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/43},name:eth1/43,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/44},name:eth1/44,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/5},name:eth1/5,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.114.11,prefix-length:24},ip:10.3.114.11}}}},subinterface:{index:10},subinterface:{index:20}}},interface:{config:{name:eth1/34},name:eth1/34,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/23},name:eth1/23,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/21},name:eth1/21,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/28},name:eth1/28,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/22},name:eth1/22,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/24},name:eth1/24,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/55},name:eth1/55,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/33},name:eth1/33,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/11},name:eth1/11,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/64},name:eth1/64,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/41},name:eth1/41,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/13},name:eth1/13,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/45},name:eth1/45,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/2},name:eth1/2,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.111.11,prefix-length:24},ip:10.3.111.11}}}}},routed-vlan:{ipv4:{addresses:{address:{config:{ip:10.3.111.11,prefix-length:24},ip:10.3.111.11}}}}},interface:{config:{name:eth1/63},name:eth1/63,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/60},name:eth1/60,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/62},name:eth1/62,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/17},name:eth1/17,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/59},name:eth1/59,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/46},name:eth1/46,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/50},name:eth1/50,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/20},name:eth1/20,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/57},name:eth1/57,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/6},name:eth1/6,subinterfaces:{subinterface:{index:0,ipv4:{addresses:{address:{config:{ip:10.3.115.11,prefix-length:24},ip:10.3.115.11}}}},subinterface:{index:20},subinterface:{index:10}}},interface:{config:{name:eth1/26},name:eth1/26,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/51},name:eth1/51,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/15},name:eth1/15,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/32},name:eth1/32,subinterfaces:{subinterface:{index:0}}},interface:{config:{name:eth1/30},name:eth1/30,subinterfaces:{subinterface:{index:0}}},xmlns:http://openconfig.net/yang/interfaces}}

This makes the json check impossible.

How can I pass the data without losing the double quotes or anything else?
Or is this an issue I should report?

it seems to be a bash behaviour which removes the double quotes before passing the parameter.

The solution is to pass the parameter in simple-quoted double-quotes like that:

  • name: Checking for duplicate keys in json answer
    local_action: script /home/actionmystique/Bash/Scripts/json-check-duplicate-keys.sh ‘“{{ uri_return.content }}”’
    register: json_check_duplicate_keys
    failed_when: json_check_duplicate_keys.stderr

“Checking /tmp/data.json…”,
“----”,
“Duplicate keys found in /tmp/data.json:”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* subinterface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”,
“* interface”