diff --git a/test/test_backends.py b/test/test_backends.py index 39cdecba..131e35da 100644 --- a/test/test_backends.py +++ b/test/test_backends.py @@ -212,6 +212,13 @@ def get_vars(host): "host.name": "host", }, ), + ( + {}, + b"host ansible_host=vsock%555", + { + "host.name": "vsock%555", + }, + ), ( {}, b"host ansible_connection=smart", diff --git a/testinfra/utils/ansible_runner.py b/testinfra/utils/ansible_runner.py index eebaa553..69c3997b 100644 --- a/testinfra/utils/ansible_runner.py +++ b/testinfra/utils/ansible_runner.py @@ -17,6 +17,7 @@ import json import os import tempfile +import urllib.parse from collections.abc import Iterator from typing import Any, Callable, Optional, Union @@ -214,7 +215,7 @@ def get_config( if version == 6: spec += "[" + testinfra_host + "]" else: - spec += testinfra_host + spec += urllib.parse.quote(testinfra_host) if port: spec += f":{port}" return testinfra.get_host(spec, **kwargs)