I want to convert ansible-init file into json. So, I just use this code: common_shared file:
 [sql]
 x.com
 [yps_db]
 y.com
 [ems_db]
 c.com
 [scc_db]
 d.com
 [all:vars]
 server_url="http://x.com/x"
 app_host=abc.com
 server_url="https://x.com"
 [haproxy]
 1.1.1.1    manual_hostname=abc instance_id=i-dddd
 2.2.2.2     manual_hostname=xyz instance_id=i-cccc
For converting Ansible INI file in JSON:
 import json
 options= {} 
 f = open('common_shared')
 x = f.read()
 config_entries = x.split()
 for key,value in zip(config_entries[0::2], config_entries[1::2]):
  cleaned_key = key.replace("[",'').replace("]",'')
  options[cleaned_key]=value
  print json.dumps(options,indent=4,ensure_ascii=False)
But it will print this result:
{
"scc_db": "xxx", 
"haproxy": "x.x.x.x", 
"manual_hostname=xxx": "instance_id=xx", 
"ems_db": "xxx", 
"yps_db": "xxx", 
"all:vars": "yps_server_url=\"xxx\"", 
"1.1.1.5": "manual_hostname=xxx", 
"sql": "xxx", 
"xxx": "scc_server_url=xxxx\""
}
But I wanted to print result in proper JSON format but not able to understand how. I tried config parser but didn't get help to print it in desired format.
 
     
     
    