summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-12-25 11:09:04 +0200
committerLars Wirzenius <liw@liw.fi>2019-12-25 11:09:04 +0200
commit9834c2105220c8a925ec6afdac1ce2003636ac31 (patch)
tree6284284f0adaaf860ce97779855ac868e73b315f
parentc39909d438c46f669bda1d20c7c0a1e597705210 (diff)
downloadvmdb2-9834c2105220c8a925ec6afdac1ce2003636ac31.tar.gz
Change: set Ansible var rootfs_tarball to --rootfs-tarball value
This allows the playbook to use the tarball given to vmdb2, rather than hardcoding a value.
-rw-r--r--vmdb/plugins/ansible_plugin.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/vmdb/plugins/ansible_plugin.py b/vmdb/plugins/ansible_plugin.py
index 9620535..cedf24d 100644
--- a/vmdb/plugins/ansible_plugin.py
+++ b/vmdb/plugins/ansible_plugin.py
@@ -40,16 +40,23 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
tag = step['ansible']
playbook = step['playbook']
mount_point = state.tags.get_mount_point(tag)
+ rootfs_tarball = settings['rootfs-tarball']
state.ansible_inventory = self.create_inventory(mount_point)
vmdb.progress(
'Created {} for Ansible inventory'.format(state.ansible_inventory))
+ vars_filename = self.create_vars(rootfs_tarball)
+ vmdb.progress(
+ 'Created {} for Ansible variables'.format(vars_filename))
+
env = dict(os.environ)
env['ANSIBLE_NOCOWS'] = '1'
vmdb.runcmd(
['ansible-playbook', '-c', 'chroot',
- '-i', state.ansible_inventory, playbook],
+ '-i', state.ansible_inventory,
+ '-e', '@{}'.format(vars_filename),
+ playbook],
env=env)
def teardown(self, step, settings, state):
@@ -62,3 +69,9 @@ class AnsibleStepRunner(vmdb.StepRunnerInterface):
os.write(fd, '[image]\n{}\n'.format(chroot).encode())
os.close(fd)
return filename
+
+ def create_vars(self, tarball):
+ fd, filename = tempfile.mkstemp()
+ os.write(fd, 'rootfs_tarball: "{}"\n'.format(tarball).encode())
+ os.close(fd)
+ return filename