Return error when write_files exists in cloud-init (#1644)

* Return error when write_files exists in cloud-init

Since the script adds a `write_files` key in cloud-init user-data, it
should return error if this key already exist in the input file.

Co-authored-by: Ondřej Budai <obudai@redhat.com>
This commit is contained in:
Diaa Sami 2021-08-20 22:24:38 +02:00 committed by GitHub
parent 9fab5def90
commit ba5f49c592
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,7 @@ import json
import os
import stat
import sys
import yaml
def octal_mode_string(mode):
@ -62,7 +63,12 @@ def main():
})
with open(f"{args.configdir}/user-data.yml") as f:
sys.stdout.write(f.read())
yml = f.read()
o = yaml.safe_load(yml)
if "write_files" in o:
print("Input file should not contain `write_files`", file=sys.stderr)
return 1
sys.stdout.write(yml)
sys.stdout.write("write_files: ")
json.dump(write_files, sys.stdout)
sys.stdout.write("\n")