# Buggy code
def _configure_module(self, module_name, module_args, task_vars=None):
    """
    Handles the loading and templating of the module code through the
    modify_module() function.
    """
    if task_vars is None:
        task_vars = dict()

    # Search module path(s) for named module.
    for mod_type in self._connection.module_implementation_preferences:
        # Check to determine if PowerShell modules are supported, and apply
        # some fixes (hacks) to module name + args.
        if mod_type == ".ps1":
            # win_stat, win_file, and win_copy are not just like their
            # python counterparts but they are compatible enough for our
            # internal usage
            if (
                module_name in ("stat", "file", "copy")
                and self._task.action != module_name
            ):
                module_name = "win_%s" % module_name

            # Remove extra quotes surrounding path parameters before sending to module.
            if (
                module_name in ("win_stat", "win_file", "win_copy", "slurp")
                and module_args
                and hasattr(self._connection._shell, "_unquote")
            ):
                for key in ("src", "dest", "path"):
                    if key in module_args:
                        module_args[key] = self._connection._shell._unquote(
                            module_args[key]
                        )

        module_path = self._shared_loader_obj.module_loader.find_plugin(
            module_name, mod_type
        )
        if module_path:
            break
    else:  # This is a for-else: http://bit.ly/1ElPkyg
        # Use Windows version of ping module to check module paths when
        # using a connection that supports .ps1 suffixes. We check specifically
        # for win_ping here, otherwise the code would look for ping.ps1
        if ".ps1" in self._connection.module_implementation_preferences:
            ping_module = "win_ping"
        else:
            ping_module = "ping"
        module_path2 = self._shared_loader_obj.module_loader.find_plugin(
            ping_module, self._connection.module_implementation_preferences
        )
        if module_path2 is not None:
            raise AnsibleError(
                "The module %s was not found in configured module paths" % (module_name)
            )
        else:
            raise AnsibleError(
                "The module %s was not found in configured module paths. "
                "Additionally, core modules are missing. If this is a checkout, "
                "run 'git pull --rebase' to correct this problem." % (module_name)
            )

    # insert shared code and arguments into the module
    final_environment = dict()
    self._compute_environment_string(final_environment)

    (module_data, module_style, module_shebang) = modify_module(
        module_name,
        module_path,
        module_args,
        task_vars=task_vars,
        module_compression=self._play_context.module_compression,
        async_timeout=self._task.async_val,
        become=self._play_context.become,
        become_method=self._play_context.become_method,
        become_user=self._play_context.become_user,
        become_password=self._play_context.become_pass,
        environment=final_environment,
    )

    return (module_style, module_shebang, module_data, module_path)


# Traceback (ImportError)
$ python /Users/will/.ansible/tmp/ansible-tmp-1480409869.55-272491715446155/rds_instance.py execute
Traceback (most recent call last):
File "/Users/will/.ansible/tmp/ansible-tmp-1480409869.55-272491715446155/debug_dir/ansible_module_rds_instance.py", line 710, in <module>
main()
File "/Users/will/.ansible/tmp/ansible-tmp-1480409869.55-272491715446155/debug_dir/ansible_module_rds_instance.py", line 678, in main
import epdb
ImportError: No module named epdb

# Fixed code
def _configure_module(self, module_name, module_args, task_vars=None):
    """
    Handles the loading and templating of the module code through the
    modify_module() function.
    """
    if task_vars is None:
        task_vars = dict()

    # Search module path(s) for named module.
    for mod_type in self._connection.module_implementation_preferences:
        # Check to determine if PowerShell modules are supported, and apply
        # some fixes (hacks) to module name + args.
        if mod_type == ".ps1":
            # win_stat, win_file, and win_copy are not just like their
            # python counterparts but they are compatible enough for our
            # internal usage
            if (
                module_name in ("stat", "file", "copy")
                and self._task.action != module_name
            ):
                module_name = "win_%s" % module_name

            # Remove extra quotes surrounding path parameters before sending to module.
            if (
                module_name in ("win_stat", "win_file", "win_copy", "slurp")
                and module_args
                and hasattr(self._connection._shell, "_unquote")
            ):
                for key in ("src", "dest", "path"):
                    if key in module_args:
                        module_args[key] = self._connection._shell._unquote(
                            module_args[key]
                        )

        module_path = self._shared_loader_obj.module_loader.find_plugin(
            module_name, mod_type
        )
        if module_path:
            break
    else:  # This is a for-else: http://bit.ly/1ElPkyg
        # Use Windows version of ping module to check module paths when
        # using a connection that supports .ps1 suffixes. We check specifically
        # for win_ping here, otherwise the code would look for ping.ps1
        if ".ps1" in self._connection.module_implementation_preferences:
            ping_module = "win_ping"
        else:
            ping_module = "ping"
        module_path2 = self._shared_loader_obj.module_loader.find_plugin(
            ping_module, self._connection.module_implementation_preferences
        )
        if module_path2 is not None:
            raise AnsibleError(
                "The module %s was not found in configured module paths" % (module_name)
            )
        else:
            raise AnsibleError(
                "The module %s was not found in configured module paths. "
                "Additionally, core modules are missing. If this is a checkout, "
                "run 'git pull --rebase' to correct this problem." % (module_name)
            )

    # insert shared code and arguments into the module
    final_environment = dict()
    self._compute_environment_string(final_environment)

    (module_data, module_style, module_shebang) = modify_module(
        module_name,
        module_path,
        module_args,
        task_vars=task_vars,
        templar=self._templar,
        module_compression=self._play_context.module_compression,
        async_timeout=self._task.async_val,
        become=self._play_context.become,
        become_method=self._play_context.become_method,
        become_user=self._play_context.become_user,
        become_password=self._play_context.become_pass,
        environment=final_environment,
    )

    return (module_style, module_shebang, module_data, module_path)