I want to dump a dict to a yaml file without the surrounding quotes. Basically like a mapping
import yaml
windows_list = []
server_list = ['abc-def-01', 'pqr-str-02']
site_list = ['dev', 'prod']
server_dict = dict(zip(server_list, site_list))
for k,v in server_dict.items():
a = '{ SERVER: '+k+', SITE: '+v+' }'
windows_list.append(a)
final_dict = {'service':'something','servers': windows_list}
with open('config.yml', 'w') as yaml_file:
yaml.dump(final_dict, yaml_file, default_flow_style=False)
The output of config.yml is below:
service: some name
servers:
- '{ SERVER: abc-def-01, SITE: dev }'
- '{ SERVER: pqr-str-02, SITE: prod }'
I do not want the quotes around it. I want it to be a mapping without the quotes
Desired output
service: some name
servers:
- { SERVER: abc-def-01, SITE: dev }
- { SERVER: pqr-str-02, SITE: prod }
I read this post and it says its not possible to remove quotes if you have special characters, but I want to know if there is a workaround of some sort to achieve what I want.