def METHOD_NAME(self, tmp=None, task_vars=None):
    if task_vars is None:
        task_vars = dict()
    connect_timeout = int(self._task.args.get('connect_timeout', self.DEFAULT_CONNECT_TIMEOUT))
    delay = int(self._task.args.get('delay', self.DEFAULT_DELAY))
    sleep = int(self._task.args.get('sleep', self.DEFAULT_SLEEP))
    timeout = int(self._task.args.get('timeout', self.DEFAULT_TIMEOUT))
    if self._play_context.check_mode:
        display.vvv("wait_for_connection: skipping for check_mode")
        return dict(skipped=True)
    result = super(ActionModule, self).METHOD_NAME(tmp, task_vars)
    del tmp  # tmp no longer has any effect
    def ping_module_test(connect_timeout):
        ''' Test ping module, if available '''
        display.vvv("wait_for_connection: attempting ping module test")
        # re-run interpreter discovery if we ran it in the first iteration
        if self._discovered_interpreter_key:
            task_vars['ansible_facts'].pop(self._discovered_interpreter_key, None)
        # call connection reset between runs if it's there
        try:
            self._connection.reset()
        except AttributeError:
            pass
        ping_result = self._execute_module(module_name='ansible.legacy.ping', module_args=dict(), task_vars=task_vars)
        # Test module output
        if ping_result['ping'] != 'pong':
            raise Exception('ping test failed')
    start = datetime.now()
    if delay:
        time.sleep(delay)
    try:
        # If the connection has a transport_test method, use it first
        if hasattr(self._connection, 'transport_test'):
            self.do_until_success_or_timeout(self._connection.transport_test, timeout, connect_timeout, what_desc="connection port up", sleep=sleep)
        # Use the ping module test to determine end-to-end connectivity
        self.do_until_success_or_timeout(ping_module_test, timeout, connect_timeout, what_desc="ping module test", sleep=sleep)
    except TimedOutException as e:
        result['failed'] = True
        result['msg'] = to_text(e)
    elapsed = datetime.now() - start
    result['elapsed'] = elapsed.seconds
    # remove a temporary path we created
    self._remove_tmp_path(self._connection._shell.tmpdir)
    return result