summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtkapiper <andy.piper@arcticwolf.com>2023-07-11 17:38:03 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-13 06:27:01 +0000
commit8ea3ce04ac5fec917b0bd498c4723e37ae003a92 (patch)
tree790cde14f85f159bb8129b186060a3019a436186
parent0ca2c940554a2e28ad24a89d6c6839608301defa (diff)
downloadvmdb2-8ea3ce04ac5fec917b0bd498c4723e37ae003a92.tar.gz
ansible_plugin.py: specify extra_vars inline
Specifying extra_vars inline makes the variables visible in the build output, which in turn makes post-build debugging easier when things go wrong
-rw-r--r--vmdb/plugins/ansible_plugin.py17
1 files changed, 3 insertions, 14 deletions
diff --git a/vmdb/plugins/ansible_plugin.py b/vmdb/plugins/ansible_plugin.py
index ad438e3..6c96a36 100644
--- a/vmdb/plugins/ansible_plugin.py
+++ b/vmdb/plugins/ansible_plugin.py
@@ -15,11 +15,10 @@
#
# =*= License: GPL-3+ =*=
+import json
import os
import tempfile
-import yaml
-
import vmdb
@@ -56,11 +55,8 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
vmdb.progress(f"Created {inventory} for Ansible inventory")
extra_vars["rootfs_tarball"] = rootfs_tarball
- vars_file = self.create_vars_file(extra_vars)
if not hasattr(state, "ansible_vars_file"):
state.ansible_vars_file = []
- state.ansible_vars_file.append(vars_file)
- vmdb.progress(f"Created {vars_file} for Ansible variables")
env = dict(os.environ)
env["ANSIBLE_NOCOWS"] = "1"
@@ -70,6 +66,7 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
vmdb.progress(f"Using Ansible config file {config_file}")
else:
raise RuntimeError(f"Ansible config file {config_file} does not exist")
+ extra_vars_json = json.dumps(extra_vars)
vmdb.runcmd(
[
"ansible-playbook",
@@ -80,15 +77,13 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
"--tags",
ansible_tags,
"-e",
- f"@{vars_file}",
+ extra_vars_json,
playbook,
],
env=env,
)
def teardown(self, values, settings, state):
- if hasattr(state, "ansible_vars_file"):
- self.remove(state.ansible_vars_file)
if hasattr(state, "ansible_inventory"):
self.remove(state.ansible_inventory)
@@ -103,9 +98,3 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
os.write(fd, f"[{group_name}]\n{chroot}\n".encode())
os.close(fd)
return filename
-
- def create_vars_file(self, extra_vars):
- fd, filename = tempfile.mkstemp(suffix=".yaml")
- os.write(fd, yaml.dump(extra_vars).encode())
- os.close(fd)
- return filename