From 166eac93e3dbfb0685ad83aea608a4d47dca4784 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 11 Apr 2022 21:22:58 +0200 Subject: [PATCH] Handle ansible_connection type community.docker.docker Molecule's Docker driver sets ansible_connection to community.docker.docker, making testinfra.utils.ansible_runner.AnsibleRunner.get_host fail to return such a host in a Molecule test using the Docker driver. Fix this by translating "community.docker.docker" to "docker". Closes #648. --- test/test_backends.py | 9 +++++++++ testinfra/utils/ansible_runner.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/test/test_backends.py b/test/test_backends.py index fd1d5437..07dc4475 100644 --- a/test/test_backends.py +++ b/test/test_backends.py @@ -283,6 +283,15 @@ def get_vars(host): "user": None, }, ), + ( + {}, + b"host ansible_connection=community.docker.docker", + { + "NAME": "docker", + "name": "host", + "user": None, + }, + ), ( {}, b"host ansible_connection=docker ansible_become=yes ansible_become_user=u ansible_user=z ansible_host=container", diff --git a/testinfra/utils/ansible_runner.py b/testinfra/utils/ansible_runner.py index 8a650970..3cbd7bf9 100644 --- a/testinfra/utils/ansible_runner.py +++ b/testinfra/utils/ansible_runner.py @@ -68,12 +68,14 @@ def get_ansible_host(config, inventory, host, ssh_config=None, ssh_identity_file "paramiko_ssh", "local", "docker", + "community.docker.docker", "lxc", "lxd", ): # unhandled connection type, must use force_ansible=True return None connection = { + "community.docker.docker": "docker", "lxd": "lxc", "paramiko_ssh": "paramiko", "smart": "ssh",