I have a function that goes as:
def set_localrepo(self):
stream = open("file1.yml", "r")
results = yaml.load(stream)
run_cmd = results["parameters"]["tag"]["properties"]
config_list = ( 'sleep 200', '[sh, -xc, \"echo test\' test\' >> /etc/hosts\"]')
for i in range(len(config_list)):
run_cmd.append(config_list[i])
stream.close()
with open("f2.yml", "w") as yaml_file:
yaml_file.write(yaml.dump(results, default_flow_style=False, allow_unicode=True))
yaml_file.close()
In this file, I have a file1.yml skeleton and from there I am processing and writing content from list to f2.yml.
Intended output should look like:
properties:
- sleep 200
- [sh, -xc, "echo $repo_server' repo-server' >> /etc/hosts"]
But instead it looks like this:
properties:
- sleep 200
- '[sh, -xc, "echo $repo_server'' repo-server'' >> /etc/hosts"]'
I have tried multiple combinations with double \, single \, etc., but it dint work as I wanted it to be.
Please advise what can be done to resolve this problem. I suspect it has something to do with YAML dump utility and escape character combination.
Thanks in anticipation!