debian-forge/stages/io.weldr.ansible
2019-07-17 13:08:22 +02:00

33 lines
793 B
Python
Executable file

#!/usr/bin/python3
import json
import subprocess
import sys
def main(tree, options):
playbook = options["playbook"]
with open("/tmp/inventory", "w") as f:
f.write(f"osbuild-tree ansible_connection=chroot ansible_host={tree} "
f"ansible_python_interpreter=/usr/bin/python3")
with open("/tmp/playbook.yml", "w") as f:
if isinstance(playbook, str):
f.write(playbook)
else:
json.dump(playbook, f)
r = subprocess.run([
"ansible-playbook", "-v",
"--connection", "chroot",
"--inventory", "/tmp/inventory",
"/tmp/playbook.yml"
])
return r.returncode
if __name__ == '__main__':
args = json.load(sys.stdin)
ret = main(args["tree"], args["options"])
sys.exit(ret)