Fix broken command tasks in handlers

With the update to Ansible 2.5 command and shell tasks used in
handlers are broken and fail with [1]. The reason for this is that the
callback v2_playbook_on_task_start is not called anymore for
handlers. Instead the callback v2_playbook_on_handler_task_start is
called for them. This leads to a missing zuul_log_id in the handler
task and trying to log to /tmp/console-None.log. In case this file was
already created by a handler using sudo it may not be accessible which
leads to the exception.

This can be fixed by also defining v2_playbook_on_handler_task_start
in zuul_stream.

Also add a validation of zuul_log_id in the command module. This
should make it easier to spot such errors next time.

[1] Trace
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/tmp/ansible_X_j_M1/ansible_module_command.py", line 185, in follow
    with Console(log_uuid) as console:
  File "/tmp/ansible_X_j_M1/ansible_module_command.py", line 162, in __enter__
    self.logfile = open(self.logfile_name, 'ab', buffering=0)
IOError: [Errno 13] Permission denied: '/tmp/console-None.log'

Change-Id: I1978aa8faa488fec87406e1481d455d49731f867
Story: 2002528
Task: 22067
This commit is contained in:
Tobias Henkel
2018-06-12 10:15:09 +02:00
parent 8dea8a32fd
commit d94a0d6f06
4 changed files with 32 additions and 1 deletions

View File

@@ -585,6 +585,9 @@ def main():
module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable)
executable = None
if not zuul_log_id:
module.fail_json(rc=256, msg="zuul_log_id missing: %s" % module.params)
if not args or args.strip() == '':
module.fail_json(rc=256, msg="no command given")