debian-forge/stages/io.weldr.ansible
Tom Gundersen cdcfa1277e osbuild: make state handling generic
Rather than treating the dnf-cache specially, give each stage its
own state directory that they can reuse. This should obviously be
used with care by the stages in order to make the builds
reproducible.
2019-06-06 19:37:49 +02:00

30 lines
724 B
Python
Executable file

#!/usr/bin/python3
import json
import os
import subprocess
import sys
def main(tree, state, playbook):
with open("/tmp/inventory", "w") as f:
f.write(f"osbuild-tree ansible_connection=chroot ansible_host={tree} 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__':
options = json.load(sys.stdin)
sys.exit(main(**options))