# Buggy code
def __init__(self, play_context, new_stdin, *args, **kwargs):
    super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

    self.chroot = self._play_context.remote_addr

    if os.geteuid() != 0:
        raise AnsibleError("chroot connection requires running as root")

    # we're running as root on the local system so do some
    # trivial checks for ensuring 'host' is actually a chroot'able dir
    if not os.path.isdir(self.chroot):
        raise AnsibleError("%s is not a directory" % self.chroot)

    chrootsh = os.path.join(self.chroot, "bin/sh")
    # Want to check for a usable bourne shell inside the chroot.
    # is_executable() == True is sufficient.  For symlinks it
    # gets really complicated really fast.  So we punt on finding that
    # out.  As long as it's a symlink we assume that it will work
    if not (
        is_executable(chrootsh)
        or (os.path.lexists(chrootsh) and os.path.islink(chrootsh))
    ):
        raise AnsibleError(
            "%s does not look like a chrootable dir (/bin/sh missing)" % self.chroot
        )

    if os.path.isabs(self.get_option("chroot_exe")):
        self.chroot_cmd = self.get_option("chroot_exe")
    else:
        self.chroot_cmd = get_bin_path(self.get_option("chroot_exe"))

    if not self.chroot_cmd:
        raise AnsibleError(
            "chroot command (%s) not found in PATH"
            % to_native(self.get_option("chroot_exe"))
        )


# Traceback (AttributeError)
ansible 2.8.2
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516]
Using /etc/ansible/ansible.cfg as config file
Unable to parse address from hostname, leaving unchanged: Not a valid network hostname: /target
Parsed /target, inventory source with host_list plugin
META: ran handlers
The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 144, in run
res = self._execute()
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 590, in _execute
self._connection = self._get_connection(variables=variables, templar=templar)
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 892, in _get_connection
ansible_playbook_pid=to_text(os.getppid())
File "/usr/lib/python2.7/dist-packages/ansible/plugins/loader.py", line 579, in get
obj = obj(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/chroot.py", line 99, in __init__
if os.path.isabs(self.get_option('chroot_exe')):
File "/usr/lib/python2.7/dist-packages/ansible/plugins/__init__.py", line 58, in get_option
option_value = C.config.get_config_value(option, plugin_type=get_plugin_class(self), plugin_name=self._load_name, variables=hostvars)
AttributeError: 'Connection' object has no attribute '_load_name'

/target | FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

# Fixed code
def __init__(self, play_context, new_stdin, *args, **kwargs):
    super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)

    self.chroot = self._play_context.remote_addr

    if os.geteuid() != 0:
        raise AnsibleError("chroot connection requires running as root")

    # we're running as root on the local system so do some
    # trivial checks for ensuring 'host' is actually a chroot'able dir
    if not os.path.isdir(self.chroot):
        raise AnsibleError("%s is not a directory" % self.chroot)

    chrootsh = os.path.join(self.chroot, "bin/sh")
    # Want to check for a usable bourne shell inside the chroot.
    # is_executable() == True is sufficient.  For symlinks it
    # gets really complicated really fast.  So we punt on finding that
    # out.  As long as it's a symlink we assume that it will work
    if not (
        is_executable(chrootsh)
        or (os.path.lexists(chrootsh) and os.path.islink(chrootsh))
    ):
        raise AnsibleError(
            "%s does not look like a chrootable dir (/bin/sh missing)" % self.chroot
        )