Skip to content

Commit 006dad9

Browse files
committed
Follow changes in ansible shell module
Now stdout/stderr lives in json encoded module_stdout key.
1 parent 5071780 commit 006dad9

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

test/test_backends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def test_encoding(host):
8686
elif host.backend.get_connection_type() == "ansible" and host.backend.force_ansible:
8787
# XXX: this encoding issue comes directly from ansible
8888
# not sure how to handle this...
89-
assert cmd.stderr == (
90-
"ls: impossible d'accéder à '/é': " "Aucun fichier ou dossier de ce type"
89+
assert (
90+
cmd.stderr
91+
== "ls: impossible d'acc\udce9der \udce0 '/é': Aucun fichier ou dossier de ce type"
9192
)
9293
else:
9394
assert cmd.stderr_bytes == (

testinfra/backend/ansible.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13+
import json
1314
import logging
1415
import pprint
1516
from typing import Any, Optional
@@ -56,12 +57,15 @@ def run(self, command: str, *args: str, **kwargs: Any) -> base.CommandResult:
5657
if host is not None:
5758
return host.run(command)
5859
out = self.run_ansible("shell", module_args=command, check=False)
59-
return self.result(
60-
out["rc"],
61-
self.encode(command),
62-
out["stdout"],
63-
out["stderr"],
64-
)
60+
if "module_stdout" in out:
61+
data = json.loads(out["module_stdout"])
62+
stdout = data["stdout"]
63+
stderr = data["stderr"]
64+
else:
65+
# bw compat
66+
stdout = out["stdout"]
67+
stderr = out["stderr"]
68+
return self.result(out["rc"], self.encode(command), stdout, stderr)
6569

6670
def run_ansible(
6771
self, module_name: str, module_args: Optional[str] = None, **kwargs: Any

0 commit comments

Comments
 (0)