Improved Ansible and PAcker workers
This commit is contained in:
parent
db0cbaff27
commit
0ef02a64f3
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue