# Buggy code
def run(self, tmp=None, task_vars=None):
    self.load_provider()

    provider = self._task.args["provider"]

    pc = copy.deepcopy(self._play_context)
    pc.connection = "network_cli"
    pc.network_os = "ios"
    pc.port = provider["port"] or self._play_context.port or 22
    pc.remote_user = provider["username"] or self._play_context.connection_user
    pc.password = provider["password"] or self._play_context.password
    pc.become = provider["authorize"] or False
    pc.become_pass = provider["auth_pass"]

    socket_path = self._get_socket_path(pc)
    if not os.path.exists(socket_path):
        # start the connection if it isn't started
        connection = self._shared_loader_obj.connection_loader.get(
            "persistent", pc, sys.stdin
        )
        connection.exec_command("EXEC: show version")

    task_vars["ansible_socket"] = socket_path

    if self._play_context.become_method == "enable":
        self._play_context.become = False
        self._play_context.become_method = None

    return super(ActionModule, self).run(tmp, task_vars)


# Traceback (012IOError)
Feb 14 11:24:01 x260 ansible-connection: <ios01> setup connection network_cli
Feb 14 11:24:01 x260 ansible-connection: <ios01> Traceback (most recent call last):#012  File "/home/johnb/git/ansible-inc/ansible/bin/ansible-connection", line 280, in main#012    server = Server(sf_path, pc)#012  File "/home/johnb/git/ansible-inc/ansible/bin/ansible-connection", line 123, in __init__#012    self.conn = connection_loader.get(play_context.connection, play_context, sys.stdin)#012  File "/home/johnb/git/ansible-inc/ansible/lib/ansible/plugins/__init__.py", line 372, in get#012    found_in_cache=found_in_cache, class_only=class_only)#012  File "/home/johnb/git/ansible-inc/ansible/lib/ansible/plugins/__init__.py", line 387, in _display_plugin_load#012    display.debug(msg)#012  File "/home/johnb/git/ansible-inc/ansible/lib/ansible/utils/display.py", line 175, in debug#012    self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG)#012  File "/home/johnb/git/ansible-inc/ansible/lib/ansible/utils/display.py", line 133, in display#012    fileobj.flush()#012IOError: [Errno 9] Bad file descriptor

# Fixed code
def run(self, tmp=None, task_vars=None):
    provider = self.load_provider()

    pc = copy.deepcopy(self._play_context)
    pc.connection = "network_cli"
    pc.network_os = "ios"
    pc.port = provider["port"] or self._play_context.port or 22
    pc.remote_user = provider["username"] or self._play_context.connection_user
    pc.password = provider["password"] or self._play_context.password
    pc.become = provider["authorize"] or False
    pc.become_pass = provider["auth_pass"]

    socket_path = self._get_socket_path(pc)
    if not os.path.exists(socket_path):
        # start the connection if it isn't started
        connection = self._shared_loader_obj.connection_loader.get(
            "persistent", pc, sys.stdin
        )
        connection.exec_command("EXEC: show version")

    task_vars["ansible_socket"] = socket_path

    if self._play_context.become_method == "enable":
        self._play_context.become = False
        self._play_context.become_method = None

    return super(ActionModule, self).run(tmp, task_vars)