From 9834c2105220c8a925ec6afdac1ce2003636ac31 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 25 Dec 2019 11:09:04 +0200 Subject: 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. --- vmdb/plugins/ansible_plugin.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1