From 8e1c9f890a03fddd3fe13f2022726d43e3bbf17c Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 26 Aug 2021 08:32:50 +0200 Subject: [PATCH] docker_containers inventory: fix wrong default mentioned in docs, add fallback example (#194) * Fix wrong default mentioned in docs. * Add fallback example. --- plugins/inventory/docker_containers.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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