# Buggy code
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475."""
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError("Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = errcode == errno.EINTR or (
                hasattr(errno, "WSAEINTR") and errcode == errno.WSAEINTR
            )

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result


# Traceback (TypeError)
The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 138, in run
res = self._execute()
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 561, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/command.py", line 24, in run
results = merge_hash(results, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 810, in _execute_module
res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 917, in _low_level_execute_command
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 984, in exec_command
(returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 258, in wrapped
return_tuple = func(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 878, in _run
return self._bare_run(cmd, in_data, sudoable=sudoable, checkrc=checkrc)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 715, in _bare_run
events = selector.select(timeout)
File "/usr/lib/python2.7/dist-packages/ansible/compat/selectors/_selectors2.py", line 464, in select
maxevents=max_events)
File "/usr/lib/python2.7/dist-packages/ansible/compat/selectors/_selectors2.py", line 139, in _syscall_wrapper
raise OSError(errno=errno.ETIMEDOUT)
TypeError: exceptions.OSError does not take keyword arguments

fatal: [staging.bizlock.net]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

# Fixed code
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475."""
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError("Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = errcode == errno.EINTR or (
                hasattr(errno, "WSAEINTR") and errcode == errno.WSAEINTR
            )

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result