Skip to content

Commit

Permalink
fixed multiple python3 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aburston committed Dec 17, 2020
1 parent 253c62c commit 9d952a9
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions write_yaml_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@
import stat

try:

with open('data.json') as data_file:
data = json.load(data_file)
SafeDumper.add_representer(
type(None),
lambda dumper, value: dumper.represent_scalar(u'tag:yaml.org,2002:null', '')
)
with open('data.json') as data_file:
data = json.load(data_file)

for filename,conf in data.iteritems():
if ("group_vars/" in filename or "host_vars/" in filename) and (".yaml" in filename or ".yml" in filename):
try:
yaml_content = yaml.safe_dump(conf,default_flow_style=False,explicit_start = True)
with open(filename, 'w') as outfile:
outfile.write(yaml_content)
os.chmod(filename,"0775")
except:
print("Yaml is not generated")
else:
print("Inavalid File Name Found =====> "+filename)
except:
print("************** No configuration data is received **************************")
pass
SafeDumper.add_representer(
type(None),
lambda dumper, value: dumper.represent_scalar(u'tag:yaml.org,2002:null', '')
)

for filename,conf in iter(data.items()):
if ("group_vars/" in filename or "host_vars/" in filename) and (".yaml" in filename or ".yml" in filename):
try:
yaml_content = yaml.safe_dump(conf, default_flow_style=False, explicit_start = True)
with open(filename, 'w') as outfile:
outfile.write(yaml_content)
os.chmod(filename, 0o775)
except Exception as e:
print(e)
print("Yaml is not generated")
else:
print("Inavalid File Name Found =====> " + filename)

except Exception as e:
print(e)
print("************** No configuration data is received **************************")

0 comments on commit 9d952a9

Please sign in to comment.