From 0ef02a64f3eb195afa50be4e6e5047a16f43e1c3 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Mon, 22 Mar 2021 11:43:41 +0100 Subject: [PATCH] Improved Ansible and PAcker workers --- pyexecplugins/Ansible.py | 5 +++-- pyexecplugins/Packer.py | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pyexecplugins/Ansible.py b/pyexecplugins/Ansible.py index 31e0fe4..17288f2 100644 --- a/pyexecplugins/Ansible.py +++ b/pyexecplugins/Ansible.py @@ -126,10 +126,11 @@ class Ansible(PyExecPlugin): # Create play object, playbook objects use .load instead of init or new methods, # this will also automatically create the task objects from the info provided in play_source play = Play().load(play_source, variable_manager=variable_manager, loader=loader) - + logging.getLogger("pyexec").debug("Play is: %s",play) # Actually run it result = tqm.run(play) # most interesting data for a play is actually sent to the callback's methods - + logging.getLogger("pyexec").debug("Executed playsource returns: %s",result) + # we always need to cleanup child procs and the structures we use to communicate with them tqm.cleanup() if loader: diff --git a/pyexecplugins/Packer.py b/pyexecplugins/Packer.py index 4efe485..f362781 100644 --- a/pyexecplugins/Packer.py +++ b/pyexecplugins/Packer.py @@ -21,13 +21,21 @@ class Plugin(PyExecPlugin): super().__init__(data) self.template = data["template"] self.command = data.get("command", "build") + self.extra_vars = data.get("extra_vars", {}) def execute(self): fp = tempfile.NamedTemporaryFile(mode="w", delete=False, encoding='utf-8') logging.getLogger("pyexec").debug("Going to %s template %s", self.command, self.data) json.dump(self.template, fp) fp.close() - cmd = ["packer", self.command, fp.name] + cmd = ["packer", self.command ] + + for k in self.extra_vars: + cmd.append("-var") + cmd.append(k + "=" + self.extra_vars.get(k)) + + cmd.append(fp.name) + logging.getLogger("pyexec").debug("Packer command is %s", cmd) try: completed = subprocess.run(cmd, capture_output=True, text=True)