Skip to content

when testing encodings for ansible - windows hosts error occurs [venv/lib/python3.12/site-packages/testinfra/backend/ansible.py:62: KeyError] #786

Description

@marwin1991

image

>       result = host.ansible(
            "win_shell",
            f"Get-Content -Path '{file_path}' | Out-String",
            check=False,
            become=True,
            become_user="vlan8user",
            become_method="runas",
        )

test_infra.py:20: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.12/site-packages/testinfra/modules/ansible.py:43: in wrapper
    return func(self, *args, **kwargs)
venv/lib/python3.12/site-packages/testinfra/modules/ansible.py:110: in __call__
    result = self._host.backend.run_ansible(
venv/lib/python3.12/site-packages/testinfra/backend/ansible.py:72: in run_ansible
    result = self.ansible_runner.run_module(
venv/lib/python3.12/site-packages/testinfra/utils/ansible_runner.py:411: in run_module
    with open(fpath, "r", encoding=get_encoding()) as f:
venv/lib/python3.12/site-packages/testinfra/backend/ansible.py:70: in get_encoding
    return self.encoding
venv/lib/python3.12/site-packages/testinfra/backend/base.py:303: in encoding
    self._encoding = self.get_encoding()
venv/lib/python3.12/site-packages/testinfra/backend/base.py:283: in get_encoding
    cmd = self.run(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <testinfra.backend.ansible.AnsibleBackend object at 0x7f0793cdf9e0>
command = "python3 -c 'import locale;print(locale.getpreferredencoding())'"
args = ('python3',), kwargs = {'encoding': None}
out = {'ansible_facts': {'discovered_interpreter_python': '/usr/bin/python3'}, 'changed': False, 'module_stderr': 'Exception...Operation: (:) [], RuntimeException\r\n    + FullyQualifiedErrorId : BadExpression\r\n \r\n', 'module_stdout': '', ...}

    def run(
    ```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions