# Buggy code
def _build_exec_cmd(self, cmd):
    """Build the local kubectl exec command to run cmd on remote_host"""
    local_cmd = [self.transport_cmd]
    censored_local_cmd = [self.transport_cmd]

    # Build command options based on doc string
    doc_yaml = AnsibleLoader(self.documentation).get_single_data()
    for key in doc_yaml.get("options"):
        if key.endswith("verify_ssl") and self.get_option(key) != "":
            # Translate verify_ssl to skip_verify_ssl, and output as string
            skip_verify_ssl = not self.get_option(key)
            local_cmd.append(
                "{0}={1}".format(
                    self.connection_options[key], str(skip_verify_ssl).lower()
                )
            )
            censored_local_cmd.append(
                "{0}={1}".format(
                    self.connection_options[key], str(skip_verify_ssl).lower()
                )
            )
        elif (
            not key.endswith("container")
            and self.get_option(key)
            and self.connection_options.get(key)
        ):
            cmd_arg = self.connection_options[key]
            local_cmd += [cmd_arg, self.get_option(key)]
            # Redact password and token from console log
            if key.endswith(("_token", "_password")):
                censored_local_cmd += [cmd_arg, "*" * 8]

    extra_args_name = "{0}_extra_args".format(self.transport)
    if self.get_option(extra_args_name):
        local_cmd += self.get_option(extra_args_name).split(" ")
        censored_local_cmd += self.get_option(extra_args_name).split(" ")

    pod = self.get_option("{0}_pod".format(self.transport))
    if not pod:
        pod = self._play_context.remote_addr
    # -i is needed to keep stdin open which allows pipelining to work
    local_cmd += ["exec", "-i", pod]
    censored_local_cmd += ["exec", "-i", pod]

    # if the pod has more than one container, then container is required
    container_arg_name = "{0}_container".format(self.transport)
    if self.get_option(container_arg_name):
        local_cmd += ["-c", self.get_option(container_arg_name)]
        censored_local_cmd += ["-c", self.get_option(container_arg_name)]

    local_cmd += ["--"] + cmd
    censored_local_cmd += ["--"] + cmd

    return local_cmd


# Traceback (ValueError)
TASK [command] *******************************************************************************************************
task path: /home/elijah/sfw/ansible/awx/foo.yml:8
<nginx-app-proxy-85cc95c5fc-8cqdr> ESTABLISH kubectl CONNECTION
The full traceback is:
Traceback (most recent call last):
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/executor/task_executor.py", line 147, in run
res = self._execute()
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/executor/task_executor.py", line 665, in _execute
result = self._handler.run(task_vars=variables)
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-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 "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/plugins/action/__init__.py", line 790, in _execute_module
self._make_tmp_path()
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/plugins/action/__init__.py", line 353, in _make_tmp_path
tmpdir = self._remote_expand_user(self.get_shell_option('remote_tmp', default='~/.ansible/tmp'), sudoable=False)
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/plugins/action/__init__.py", line 674, in _remote_expand_user
data = self._low_level_execute_command(cmd, sudoable=False)
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/plugins/action/__init__.py", line 1085, in _low_level_execute_command
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/home/elijah/venv/python3towerqa/lib64/python3.8/site-packages/ansible/plugins/connection/kubectl.py", line 286, in exec_command
local_cmd, censored_local_cmd = self._build_exec_cmd([self._play_context.executable, '-c', cmd])
ValueError: too many values to unpack (expected 2)
fatal: [nginx-app-proxy-85cc95c5fc-8cqdr]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

# Fixed code
def _build_exec_cmd(self, cmd):
    """Build the local kubectl exec command to run cmd on remote_host"""
    local_cmd = [self.transport_cmd]
    censored_local_cmd = [self.transport_cmd]

    # Build command options based on doc string
    doc_yaml = AnsibleLoader(self.documentation).get_single_data()
    for key in doc_yaml.get("options"):
        if key.endswith("verify_ssl") and self.get_option(key) != "":
            # Translate verify_ssl to skip_verify_ssl, and output as string
            skip_verify_ssl = not self.get_option(key)
            local_cmd.append(
                "{0}={1}".format(
                    self.connection_options[key], str(skip_verify_ssl).lower()
                )
            )
            censored_local_cmd.append(
                "{0}={1}".format(
                    self.connection_options[key], str(skip_verify_ssl).lower()
                )
            )
        elif (
            not key.endswith("container")
            and self.get_option(key)
            and self.connection_options.get(key)
        ):
            cmd_arg = self.connection_options[key]
            local_cmd += [cmd_arg, self.get_option(key)]
            # Redact password and token from console log
            if key.endswith(("_token", "_password")):
                censored_local_cmd += [cmd_arg, "*" * 8]

    extra_args_name = "{0}_extra_args".format(self.transport)
    if self.get_option(extra_args_name):
        local_cmd += self.get_option(extra_args_name).split(" ")
        censored_local_cmd += self.get_option(extra_args_name).split(" ")

    pod = self.get_option("{0}_pod".format(self.transport))
    if not pod:
        pod = self._play_context.remote_addr
    # -i is needed to keep stdin open which allows pipelining to work
    local_cmd += ["exec", "-i", pod]
    censored_local_cmd += ["exec", "-i", pod]

    # if the pod has more than one container, then container is required
    container_arg_name = "{0}_container".format(self.transport)
    if self.get_option(container_arg_name):
        local_cmd += ["-c", self.get_option(container_arg_name)]
        censored_local_cmd += ["-c", self.get_option(container_arg_name)]

    local_cmd += ["--"] + cmd
    censored_local_cmd += ["--"] + cmd

    return local_cmd, censored_local_cmd