I have an yaml file as mentioned below test1.yaml
resources:
name:{get_param: vname}
ssh_keypair: {get_param: ssh_keypair}
Now I want to add test1_routable_net: { get_param: abc_routable_net } under resources of test1.yaml Here is the code which I tried
import ruamel.yaml
yaml = ruamel.yaml.YAML()
test="{ get_param: abc_routable_net }".strip(‘\’’)
with open('/tmp/test1.yaml') as fp:
data = yaml.load(fp)
data['resources'].update({‘test1_routable_net’:test})
yaml.dump(data,file('/tes2.yaml', 'w'))
output of above code is tes2.yaml
resources:
name:{get_param: vname}
ssh_keypair: {get_param: ssh_keypair}
test1_routable_net: '{ get_param: abc_routable_net }'
Desired output is
tes2.yaml
resources:
name:{get_param: vname}
ssh_keypair: {get_param: ssh_keypair}
test1_routable_net: { get_param: abc_routable_net }
I tried using test.strip('\'')
, but no use still I see single quotes for the value .... How can I remove those quotes from the value?
ryaml
is not defined anywhere, neither is the variabletest1_routable_net
. And make your input and output files valid YAML: don't make the filename part of your YAML block, I already corrected that once in your other question. Sloppiness in asking questions is a sure sign for sloppiness in programming. – Deannadeanne