diff --git a/changelogs/fragments/ansible-test-docker-network-detect.yml b/changelogs/fragments/ansible-test-docker-network-detect.yml new file mode 100644 index 00000000000..620fdc28976 --- /dev/null +++ b/changelogs/fragments/ansible-test-docker-network-detect.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix docker container IP address detection. The ``bridge`` network is no longer assumed to be the default. diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py index 75893e5dd14..5672ca1c801 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -423,7 +423,13 @@ class DockerInspect: def get_ip_address(self): # type: () -> t.Optional[str] """Return the IP address of the container for the preferred docker network.""" if self.networks: - network_name = get_docker_preferred_network_name(self.args) or 'bridge' + network_name = get_docker_preferred_network_name(self.args) + + if not network_name: + # Sort networks and use the first available. + # This assumes all containers will have access to the same networks. + network_name = sorted(self.networks.keys()).pop(0) + ipaddress = self.networks[network_name]['IPAddress'] else: ipaddress = self.network_settings['IPAddress']