Skip to content

Commit 664ace3

Browse files
Allow VSOCK in Ansible hostnames
The VSOCK address family facilitates communication between virtual machines and the host they are running on. An example: https://wiki.archlinux.org/title/QEMU#Accessing_SSH_via_vsock The separator between the "vsock" identifier and the CID can either be a forward slash (`/`) or a percent sign (`%`). `urllib.parse.urlparse` will mistake the forward slash for the beginning of the URL path, but a percent sign is accepted. ``` >>> urlparse("ansible://vsock/555") ParseResult(scheme='ansible', netloc='vsock', path='/555', params='', query='', fragment='') >>> urlparse("ansible://vsock%555") ParseResult(scheme='ansible', netloc='vsock%555', path='', params='', query='', fragment='') ```
1 parent c17794e commit 664ace3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/test_backends.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ def get_vars(host):
212212
"host.name": "host",
213213
},
214214
),
215+
(
216+
{},
217+
b"host ansible_host=vsock%555",
218+
{
219+
"host.name": "vsock%555",
220+
},
221+
),
215222
(
216223
{},
217224
b"host ansible_connection=smart",

testinfra/utils/ansible_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818
import os
1919
import tempfile
20+
import urllib.parse
2021
from collections.abc import Iterator
2122
from typing import Any, Callable, Optional, Union
2223

@@ -214,7 +215,7 @@ def get_config(
214215
if version == 6:
215216
spec += "[" + testinfra_host + "]"
216217
else:
217-
spec += testinfra_host
218+
spec += urllib.parse.quote(testinfra_host)
218219
if port:
219220
spec += f":{port}"
220221
return testinfra.get_host(spec, **kwargs)

0 commit comments

Comments
 (0)