diff --git a/plugins/inventory/docker_containers.py b/plugins/inventory/docker_containers.py index 8e3c9be3..662ca1e2 100644 --- a/plugins/inventory/docker_containers.py +++ b/plugins/inventory/docker_containers.py @@ -38,11 +38,11 @@ options: connection_type: description: - Which connection type to use the containers. - - Default is to use SSH (C(ssh)). For this, the options I(default_ip) and - I(private_ssh_port) are used. + - One way to connect to containers is to use SSH (C(ssh)). For this, the options I(default_ip) and + I(private_ssh_port) are used. This requires that a SSH daemon is running inside the containers. - Alternatively, C(docker-cli) selects the R(docker connection plugin,ansible_collections.community.docker.docker_connection), - and C(docker-api) selects the + and C(docker-api) (default) selects the R(docker_api connection plugin,ansible_collections.community.docker.docker_api_connection). - When C(docker-api) is used, all Docker daemon configuration values are passed from the inventory plugin to the connection plugin. This can be controlled with I(configure_docker_daemon). @@ -138,6 +138,14 @@ keyed_groups: # Add Linux hosts to an os_linux group - prefix: os key: docker_platform + +# Example using SSH connection with an explicit fallback for when port 22 hasn't been +# exported: use container name as ansible_ssh_host and 22 as ansible_ssh_port +plugin: community.docker.docker_containers +connection_type: ssh +compose: + ansible_ssh_host: ansible_ssh_host | default(docker_name[1:], true) + ansible_ssh_port: ansible_ssh_port | default(22, true) ''' import re