-name:Get facts on current container
+community.docker.current_container_facts:
+
+-name:Print information on current container when running in a container
+ansible.builtin.debug:
+msg:"ContainerIDis{{ansible_module_container_id}}"
+when:ansible_module_running_in_container
+
Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
+
+
+
Key
+
Description
+
+
+
+
+
ansible_module_container_id
+
string
+
+
The detected container ID.
+
Contains an empty string if no container was detected.
+
Returned: always
+
+
+
+
ansible_module_container_type
+
string
+
+
The detected container environment.
+
Contains an empty string if no container was detected, or a non-empty string identifying the container environment.
+
docker indicates that the module ran inside a regular Docker container.
+
azure_pipelines indicates that the module ran on Azure Pipelines. This seems to no longer be reported.
+
github_actions indicates that the module ran inside a Docker container on GitHub Actions. It is supported since community.docker 2.4.0.
+
podman indicates that the module ran inside a regular Podman container. It is supported since community.docker 3.3.0.
+
Returned: always
+
Can only return:
+
+
""
+
"docker"
+
"azure_pipelines"
+
"github_actions"
+
"podman"
+
+
+
+
+
ansible_module_running_in_container
+
boolean
+
+
Whether the module was able to detect that it runs in a container or not.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this connection plugin,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_api.
Run commands or put/fetch files to an existing docker container.
+
Uses the requests library to interact directly with the Docker daemon instead of using the Docker CLI. Use the community.docker.docker connection plugin if you want to use the Docker CLI.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
Configuration:
+
+
Variable: ansible_docker_api_version
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
Configuration:
+
+
Variable: ansible_docker_ca_cert
+
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
Configuration:
+
+
Variable: ansible_docker_client_cert
+
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
Configuration:
+
+
Variable: ansible_docker_client_key
+
+
+
+
+
container_timeout
+
integer
+
+
Controls how long we can wait to access reading output from the container once execution started.
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
Configuration:
+
+
Variable: ansible_docker_ssl_version
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
Configuration:
+
+
Variable: ansible_docker_timeout
+
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
Configuration:
+
+
Variable: ansible_docker_tls
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
Configuration:
+
+
Variable: ansible_docker_tls_hostname
+
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_compose.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
build
+
boolean
+
+
Use with statepresent to always build images prior to starting the application.
+
Same as running docker-composebuild with the pull option.
+
Images will only be rebuilt if Docker detects a change in the Dockerfile or build directory contents.
+
Use the nocache option to ignore the image cache when performing the build.
+
If an existing image is replaced, services using the image will be recreated unless recreate is never.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
definition
+
dictionary
+
+
Compose file describing one or more services, networks and volumes.
+
Mutually exclusive with project_src and files.
+
+
+
+
dependencies
+
boolean
+
+
When state is present specify whether or not to include linked services.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
env_file
+
path
+
added in community.docker 1.9.0
+
+
By default environment files are loaded from a .env file located directly under the project_src directory.
+
env_file can be used to specify the path of a custom environment file instead.
+
The path is relative to the project_src directory.
+
Requires docker-compose version 1.25.0 or greater.
+
Note: docker-compose versions <=1.28 load the env file from the current working directory of the docker-compose command rather than project_src.
+
+
+
+
files
+
list / elements=path
+
+
List of Compose file names relative to project_src. Overrides docker-compose.yml or docker-compose.yaml.
+
Files are loaded and merged in the order given.
+
+
+
+
hostname_check
+
boolean
+
+
Whether or not to check the Docker daemon’s hostname against the name provided in the client certificate.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
nocache
+
boolean
+
+
Use with the build option to ignore the cache during the image build process.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
profiles
+
list / elements=string
+
added in community.docker 1.8.0
+
+
List of profiles to enable when starting services.
+
Equivalent to docker-compose--profile.
+
Requires docker-compose version 1.28.0 or greater.
+
+
+
+
project_name
+
string
+
+
Provide a project name. If not provided, the project name is taken from the basename of project_src.
+
Required when definition is provided.
+
+
+
+
project_src
+
path
+
+
Path to a directory containing a docker-compose.yml or docker-compose.yaml file.
+
Mutually exclusive with definition.
+
Required when no definition is provided.
+
+
+
+
pull
+
boolean
+
+
Use with statepresent to always pull images prior to starting the application.
+
Same as running docker-composepull.
+
When a new image is pulled, services using the image will be recreated unless recreate is never.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
recreate
+
string
+
+
By default containers will be recreated when their configuration differs from the service definition.
+
Setting to never ignores configuration differences and leaves existing containers unchanged.
+
Setting to always forces recreation of all existing containers.
+
Choices:
+
+
"always"
+
"never"
+
"smart"← (default)
+
+
+
+
+
remove_images
+
string
+
+
Use with stateabsent to remove all images or only local images.
+
Choices:
+
+
"all"
+
"local"
+
+
+
+
+
remove_orphans
+
boolean
+
+
Remove containers for services not defined in the Compose file.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
remove_volumes
+
boolean
+
+
Use with stateabsent to remove data volumes.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
restarted
+
boolean
+
+
Use with statepresent to restart all containers defined in the Compose file.
+
If services is defined, only the containers listed there will be restarted.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
scale
+
dictionary
+
+
When state is present scale services. Provide a dictionary of key/value pairs where the key is the name of the service and the value is an integer count for the number of containers.
+
+
+
+
services
+
list / elements=string
+
+
When state is present run docker-composeup resp. docker-composestop (with stopped) resp. docker-composerestart (with restarted) on a subset of services.
+
If empty, which is the default, the operation will be performed on all services defined in the Compose file (or inline definition).
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
Desired state of the project.
+
Specifying present is the same as running docker-composeup resp. docker-composestop (with stopped) resp. docker-composerestart (with restarted).
+
Specifying absent is the same as running docker-composedown.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
stopped
+
boolean
+
+
Use with statepresent to stop all containers defined in the Compose file.
+
If services is defined, only the containers listed there will be stopped.
+
Requires docker-compose version 1.17.0 or greater for full support. For older versions, the services will first be started and then stopped when the service is supposed to be created as stopped.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
timeout
+
integer
+
+
Timeout in seconds for container shutdown when attached or when containers are already running.
+
By default compose will use a 10s timeout unless default_grace_period is defined for a particular service in the project_src.
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
Currently ignored for this module, but might suddenly be supported later on.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_config.
Create and remove Docker configs in a Swarm environment. Similar to dockerconfigcreate and dockerconfigrm.
+
Adds to the metadata of new configs ‘ansible_key’, an encrypted hash representation of the data, which is then used in future runs to test if a config has changed. If ‘ansible_key’ is not present, then a config will not be updated unless the force option is set.
+
Updates to configs are performed by removing the config and creating it again.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.30
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). This module does *not* work with docker-py.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
data
+
string
+
+
The value of the config.
+
Mutually exclusive with data_src. One of data and data_src is required if state=present.
+
+
+
+
data_is_b64
+
boolean
+
+
If set to true, the data is assumed to be Base64 encoded and will be decoded before being used.
+
To use binary data, it is better to keep it Base64 encoded and let it be decoded by this option.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
data_src
+
path
+
added in community.docker 1.10.0
+
+
The file on the target from which to read the config.
+
Mutually exclusive with data. One of data and data_src is required if state=present.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
force
+
boolean
+
+
Use with state present to always remove and recreate an existing config.
+
If true, an existing config will be replaced, even if it has not been changed.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
labels
+
dictionary
+
+
A map of key:value meta data, where both the key and value are expected to be a string.
+
If new meta data is provided, or existing meta data is modified, the config will be updated by removing it and creating it again.
+
+
+
+
name
+
string / required
+
+
The name of the config.
+
+
+
+
rolling_versions
+
boolean
+
added in community.docker 2.2.0
+
+
If set to true, configs are created with an increasing version number appended to their name.
+
Adds a label containing the version number to the managed configs with the name ansible_version.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
Set to present, if the config should exist, and absent, if it should not.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
template_driver
+
string
+
added in community.docker 2.5.0
+
+
Set to golang to use a Go template in data or a Go template file in data_src.
+
Choices:
+
+
"golang"
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
versions_to_keep
+
integer
+
added in community.docker 2.2.0
+
+
When using rolling_versions, the number of old versions of the config to keep.
+
Extraneous old configs are deleted after the new one is created.
+
Set to -1 to keep everything or to 0 or 1 to keep only the current one.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
-name:Create config foo (from a file on the control machine)
+community.docker.docker_config:
+name:foo
+# If the file is JSON or binary, Ansible might modify it (because
+# it is first decoded and later re-encoded). Base64-encoding the
+# file directly after reading it prevents this to happen.
+data:"{{lookup('file','/path/to/config/file')|b64encode}}"
+data_is_b64:true
+state:present
+
+-name:Create config foo (from a file on the target machine)
+community.docker.docker_config:
+name:foo
+data_src:/path/to/config/file
+state:present
+
+-name:Change the config data
+community.docker.docker_config:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+state:present
+
+-name:Add a new label
+community.docker.docker_config:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+# Adding a new label will cause a remove/create of the config
+two:'2'
+state:present
+
+-name:No change
+community.docker.docker_config:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+# Even though 'two' is missing, there is no change to the existing config
+state:present
+
+-name:Update an existing label
+community.docker.docker_config:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:monkey# Changing a label will cause a remove/create of the config
+one:'1'
+state:present
+
+-name:Force the (re-)creation of the config
+community.docker.docker_config:
+name:foo
+data:Goodnight everyone!
+force:true
+state:present
+
+-name:Remove config foo
+community.docker.docker_config:
+name:foo
+state:absent
+
Run commands or put/fetch files to an existing docker container.
+
Uses the Docker CLI to execute commands in the container. If you prefer to directly connect to the Docker daemon, use the community.docker.docker_api connection plugin.
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_container_copy_into.
To copy files in a non-running container, you must provide the owner_id and group_id options. This is also necessary if the container does not contain a /bin/sh shell with an id tool.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
container
+
string / required
+
+
The name of the container to copy files to.
+
+
+
+
container_path
+
string / required
+
+
Path to a file inside the Docker container.
+
Must be an absolute path.
+
+
+
+
content
+
string
+
+
The file’s content.
+
If you plan to provide binary data, provide it pre-encoded to base64, and set content_is_b64=true.
+
Mutually exclusive with path. One of content and path is required.
+
+
+
+
content_is_b64
+
boolean
+
+
If set to true, the content in content is assumed to be Base64 encoded and will be decoded before being used.
+
To use binary content, it is better to keep it Base64 encoded and let it be decoded by this option. Otherwise you risk the data to be interpreted as UTF-8 and corrupted.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
follow
+
boolean
+
+
This flag indicates that filesystem links in the Docker container, if they exist, should be followed.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
force
+
boolean
+
+
If set to true, force writing the file (without performing any idempotency checks).
+
If set to false, only write the file if it does not exist on the target. If a filesystem object exists at the destination, the module will not do any change.
+
If this option is not specified, the module will be idempotent. To verify idempotency, it will try to get information on the filesystem object in the container, and if everything seems to match will download the file from the container to compare it to the file to upload.
+
Choices:
+
+
false
+
true
+
+
+
+
+
group_id
+
integer
+
+
The group ID to use when writing the file to disk.
+
If provided, owner_id must also be provided.
+
If not provided, the module will try to determine the user and group ID for the current user in the container. This will only work if /bin/sh is present in the container and the id binary or shell builtin is available. Also the container must be running.
+
+
+
+
local_follow
+
boolean
+
+
This flag indicates that filesystem links in the source tree (where the module is executed), if they exist, should be followed.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
mode
+
integer
+
+
The file mode to use when writing the file to disk.
+
Will use the file’s mode from the source system if this option is not provided.
+
+
+
+
owner_id
+
integer
+
+
The owner ID to use when writing the file to disk.
+
If provided, group_id must also be provided.
+
If not provided, the module will try to determine the user and group ID for the current user in the container. This will only work if /bin/sh is present in the container and the id binary or shell builtin is available. Also the container must be running.
+
+
+
+
path
+
path
+
+
Path to a file on the managed node.
+
Mutually exclusive with content. One of content and path is required.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Copy a file into the container
+community.docker.docker_container_copy_into:
+container:mydata
+path:/home/user/data.txt
+container_path:/data/input.txt
+
+-name:Copy a file into the container with owner, group, and mode set
+community.docker.docker_container_copy_into:
+container:mydata
+path:/home/user/bin/runme.o
+container_path:/bin/runme
+owner:0# root
+group:0# root
+mode:0o755# readable and executable by all users, writable by root
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_container_exec.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
argv
+
list / elements=string
+
+
The command to execute.
+
Since this is a list of arguments, no quoting is needed.
+
Exactly one of argv and command must be specified.
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
chdir
+
string
+
+
The directory to run the command in.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
command
+
string
+
+
The command to execute.
+
Exactly one of argv and command must be specified.
+
+
+
+
container
+
string / required
+
+
The name of the container to execute the command in.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
detach
+
boolean
+
added in community.docker 2.1.0
+
+
Whether to run the command synchronously (detach=false, default) or asynchronously (detach=true).
+
If set to true, stdin cannot be provided, and the return values stdout, stderr and rc are not returned.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
env
+
dictionary
+
added in community.docker 2.1.0
+
+
Dictionary of environment variables with their respective values to be passed to the command ran inside the container.
+
Values which might be parsed as numbers, booleans or other types by the YAML parser must be quoted (for example "true") in order to avoid data loss.
+
Please note that if you are passing values in with Jinja2 templates, like "{{value}}", you need to add |string to prevent Ansible to convert strings such as "true" back to booleans. The correct way is to use "{{value|string}}".
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
stdin
+
string
+
+
Set the stdin of the command directly to the specified value.
+
Can only be used if detach=false.
+
+
+
+
stdin_add_newline
+
boolean
+
+
If set to true, appends a newline to stdin.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
strip_empty_ends
+
boolean
+
+
Strip empty lines from the end of stdout/stderr in result.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
tty
+
boolean
+
+
Whether to allocate a TTY.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
user
+
string
+
+
If specified, the user to execute this command with.
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_container_info.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
name
+
string / required
+
+
The name of the container to inspect.
+
When identifying an existing container name may be a name or a long or short container ID.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_container.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
auto_remove
+
boolean
+
+
Enable auto-removal of the container on daemon side when the container’s process exits.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
blkio_weight
+
integer
+
+
Block IO (relative weight), between 10 and 1000.
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
cap_drop
+
list / elements=string
+
+
List of capabilities to drop from the container.
+
+
+
+
capabilities
+
list / elements=string
+
+
List of capabilities to add to the container.
+
This is equivalent to dockerrun--cap-add, or the docker-compose option cap_add.
+
+
+
+
cgroup_parent
+
string
+
added in community.docker 1.1.0
+
+
Specify the parent cgroup for the container.
+
+
+
+
cgroupns_mode
+
string
+
added in community.docker 3.0.0
+
+
Specify the cgroup namespace mode for the container.
+
The Docker CLI calls this simply cgroupns.
+
Choices:
+
+
"host"
+
"private"
+
+
+
+
+
cleanup
+
boolean
+
+
Use with detach=false to remove the container after successful execution.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
command
+
any
+
+
Command to execute when the container starts. A command may be either a string or a list.
+
Prior to version 2.4, strings were split on commas.
+
See command_handling for differences in how strings and lists are handled.
+
+
+
+
command_handling
+
string
+
added in community.docker 1.9.0
+
+
The default behavior for command (when provided as a list) and entrypoint is to convert them to strings without considering shell quoting rules. (For comparing idempotency, the resulting string is split considering shell quoting rules.)
+
Also, setting command to an empty list of string, and setting entrypoint to an empty list will be handled as if these options are not specified. This is different from idempotency handling for other container-config related options.
+
When this is set to compatibility, which was the default until community.docker 3.0.0, the current behavior will be kept.
+
When this is set to correct, these options are kept as lists, and an empty value or empty list will be handled correctly for idempotency checks. This has been the default since community.docker 3.0.0.
+
Choices:
+
+
"compatibility"
+
"correct"← (default)
+
+
+
+
+
comparisons
+
dictionary
+
+
Allows to specify how properties of existing containers are compared with module options to decide whether the container should be recreated / updated or not.
+
Only options which correspond to the state of a container as handled by the Docker daemon can be specified, as well as networks.
+
Must be a dictionary specifying for an option one of the keys strict, ignore and allow_more_present.
+
If strict is specified, values are tested for equality, and changes always result in updating or restarting. If ignore is specified, changes are ignored.
+
allow_more_present is allowed only for lists, sets and dicts. If it is specified for lists or sets, the container will only be updated or restarted if the module option contains a value which is not present in the container’s options. If the option is specified for a dict, the container will only be updated or restarted if the module option contains a key which is not present in the container’s option, or if the value of a key present differs.
+
The wildcard option * can be used to set one of the default values strict or ignore to all comparisons which are not explicitly set to other values.
+
See the examples for details.
+
+
+
+
container_default_behavior
+
string
+
+
In older versions of this module, various module options used to have default values. This caused problems with containers which use different values for these options.
+
The default value is now no_defaults. To restore the old behavior, set it to compatibility, which will ensure that the default values are used when the values are not explicitly specified by the user.
+
This affects the auto_remove, detach, init, interactive, memory, paused, privileged, read_only and tty options.
+
Choices:
+
+
"compatibility"
+
"no_defaults"← (default)
+
+
+
+
+
cpu_period
+
integer
+
+
Limit CPU CFS (Completely Fair Scheduler) period.
+
See cpus for an easier to use alternative.
+
+
+
+
cpu_quota
+
integer
+
+
Limit CPU CFS (Completely Fair Scheduler) quota.
+
See cpus for an easier to use alternative.
+
+
+
+
cpu_shares
+
integer
+
+
CPU shares (relative weight).
+
+
+
+
cpus
+
float
+
+
Specify how much of the available CPU resources a container can use.
+
A value of 1.5 means that at most one and a half CPU (core) will be used.
+
+
+
+
cpuset_cpus
+
string
+
+
CPUs in which to allow execution 1,3 or 1-3.
+
+
+
+
cpuset_mems
+
string
+
+
Memory nodes (MEMs) in which to allow execution 0-3 or 0,1.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
default_host_ip
+
string
+
added in community.docker 1.2.0
+
+
Define the default host IP to use.
+
Must be an empty string, an IPv4 address, or an IPv6 address.
By default, the module will try to auto-detect this value from the bridge network’s com.docker.network.bridge.host_binding_ipv4 option. If it cannot auto-detect it, it will fall back to 0.0.0.0.
+
+
+
+
detach
+
boolean
+
+
Enable detached mode to leave the container running in background.
+
If disabled, the task will reflect the status of the container run (failed if the command failed).
+
If container_default_behavior is set to compatibility, this option has a default of true.
+
Choices:
+
+
false
+
true
+
+
+
+
+
device_read_bps
+
list / elements=dictionary
+
+
List of device path and read rate (bytes per second) from device.
+
+
+
+
path
+
string / required
+
+
Device path in the container.
+
+
+
+
rate
+
string / required
+
+
Device read limit in format <number>[<unit>].
+
Number is a positive integer. Unit can be one of B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
+
+
+
device_read_iops
+
list / elements=dictionary
+
+
List of device and read rate (IO per second) from device.
+
+
+
+
path
+
string / required
+
+
Device path in the container.
+
+
+
+
rate
+
integer / required
+
+
Device read limit.
+
Must be a positive integer.
+
+
+
+
device_requests
+
list / elements=dictionary
+
added in community.docker 0.1.0
+
+
Allows to request additional resources, such as GPUs.
+
+
+
+
capabilities
+
list / elements=list
+
+
List of lists of strings to request capabilities.
+
The top-level list entries are combined by OR, and for every list entry, the entries in the list it contains are combined by AND.
List of device and write rate (bytes per second) to device.
+
+
+
+
path
+
string / required
+
+
Device path in the container.
+
+
+
+
rate
+
string / required
+
+
Device read limit in format <number>[<unit>].
+
Number is a positive integer. Unit can be one of B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
+
+
+
device_write_iops
+
list / elements=dictionary
+
+
List of device and write rate (IO per second) to device.
+
+
+
+
path
+
string / required
+
+
Device path in the container.
+
+
+
+
rate
+
integer / required
+
+
Device read limit.
+
Must be a positive integer.
+
+
+
+
devices
+
list / elements=string
+
+
List of host device bindings to add to the container.
+
Each binding is a mapping expressed in the format <path_on_host>:<path_in_container>:<cgroup_permissions>.
+
+
+
+
dns_opts
+
list / elements=string
+
+
List of DNS options.
+
+
+
+
dns_search_domains
+
list / elements=string
+
+
List of custom DNS search domains.
+
+
+
+
dns_servers
+
list / elements=string
+
+
List of custom DNS servers.
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
domainname
+
string
+
+
Container domainname.
+
+
+
+
entrypoint
+
list / elements=string
+
+
Command that overwrites the default ENTRYPOINT of the image.
+
See command_handling for differences in how strings and lists are handled.
+
+
+
+
env
+
dictionary
+
+
Dictionary of key,value pairs.
+
Values which might be parsed as numbers, booleans or other types by the YAML parser must be quoted (for example "true") in order to avoid data loss.
+
Please note that if you are passing values in with Jinja2 templates, like "{{value}}", you need to add |string to prevent Ansible to convert strings such as "true" back to booleans. The correct way is to use "{{value|string}}".
+
+
+
+
env_file
+
path
+
+
Path to a file, present on the target, containing environment variables FOO=BAR.
+
If variable also present in env, then the env value will override.
+
+
+
+
etc_hosts
+
dictionary
+
+
Dict of host-to-IP mappings, where each host name is a key in the dictionary. Each host name will be added to the container’s /etc/hosts file.
+
+
+
+
+
+
exposed_ports
+
aliases: exposed, expose
+
list / elements=string
+
+
List of additional container ports which informs Docker that the container listens on the specified network ports at runtime.
+
If the port is already exposed using EXPOSE in a Dockerfile, it does not need to be exposed again.
+
+
+
+
+
force_kill
+
aliases: forcekill
+
boolean
+
+
Use the kill command when stopping a running container.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
groups
+
list / elements=string
+
+
List of additional group names and/or IDs that the container process will run as.
+
+
+
+
healthcheck
+
dictionary
+
+
Configure a check that is run to determine whether or not containers for this service are “healthy”.
interval, timeout and start_period are specified as durations. They accept duration as a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
+
+
+
interval
+
string
+
+
Time between running the check.
+
The default used by the Docker daemon is 30s.
+
+
+
+
retries
+
integer
+
+
Consecutive number of failures needed to report unhealthy.
+
The default used by the Docker daemon is 3.
+
+
+
+
start_period
+
string
+
+
Start period for the container to initialize before starting health-retries countdown.
+
The default used by the Docker daemon is 0s.
+
+
+
+
test
+
any
+
+
Command to run to check health.
+
Must be either a string or a list. If it is a list, the first item must be one of NONE, CMD or CMD-SHELL.
+
+
+
+
timeout
+
string
+
+
Maximum time to allow one check to run.
+
The default used by the Docker daemon is 30s.
+
+
+
+
hostname
+
string
+
+
The container’s hostname.
+
+
+
+
ignore_image
+
boolean
+
+
When state is present or started, the module compares the configuration of an existing container to requested configuration. The evaluation includes the image version. If the image version in the registry does not match the container, the container will be recreated. You can stop this behavior by setting ignore_image to true.
+
Warning: This option is ignored if image:ignore or *:ignore is specified in the comparisons option.
+
This option is deprecated since community.docker 3.2.0 and will be removed in community.docker 4.0.0. Use image:ignore in comparisons instead of ignore_image=true.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
image
+
string
+
+
Repository path and tag used to create the container. If an image is not found or pull is true, the image will be pulled from the registry. If no tag is included, latest will be used.
+
Can also be an image ID. If this is the case, the image is assumed to be available locally. The pull option is ignored for this case.
+
+
+
+
image_comparison
+
string
+
added in community.docker 3.0.0
+
+
Determines which image to use for idempotency checks that depend on image parameters.
+
The default, desired-image, will use the image that is provided to the module via the image parameter.
+
current-image will use the image that the container is currently using, if the container exists. It falls back to the image that is provided in case the container does not yet exist.
+
This affects the env, env_file, exposed_ports, labels, and volumes options.
+
Choices:
+
+
"desired-image"← (default)
+
"current-image"
+
+
+
+
+
image_label_mismatch
+
string
+
added in community.docker 2.6.0
+
+
How to handle labels inherited from the image that are not set explicitly.
+
When ignore, labels that are present in the image but not specified in labels will be ignored. This is useful to avoid having to specify the image labels in labels while keeping labels comparisonsstrict.
+
When fail, if there are labels present in the image which are not set from labels, the module will fail. This prevents introducing unexpected labels from the base image.
+
Warning: This option is ignored unless labels:strict or *:strict is specified in the comparisons option.
+
Choices:
+
+
"ignore"← (default)
+
"fail"
+
+
+
+
+
image_name_mismatch
+
string
+
added in community.docker 3.2.0
+
+
Determines what the module does if the image matches, but the image name in the container’s configuration does not match the image name provided to the module.
+
This is ignored if image:ignore is set in comparisons.
+
If set to recreate the container will be recreated.
+
If set to ignore the container will not be recreated because of this. It might still get recreated for other reasons. This has been the default behavior of the module for a long time, but might not be what users expect.
+
Choices:
+
+
"recreate"
+
"ignore"← (default)
+
+
+
+
+
init
+
boolean
+
+
Run an init inside the container that forwards signals and reaps processes.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
interactive
+
boolean
+
+
Keep stdin open after a container is launched, even if not attached.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
ipc_mode
+
string
+
+
Set the IPC mode for the container.
+
Can be one of container:<name|id> to reuse another container’s IPC namespace or host to use the host’s IPC namespace within the container.
+
+
+
+
keep_volumes
+
boolean
+
+
Retain anonymous volumes associated with a removed container.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
kernel_memory
+
string
+
+
Kernel memory limit in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte). Minimum is 4M.
+
Omitting the unit defaults to bytes.
+
+
+
+
kill_signal
+
string
+
+
Override default signal used to kill a running container.
+
+
+
+
labels
+
dictionary
+
+
Dictionary of key value pairs.
+
+
+
+
links
+
list / elements=string
+
+
List of name aliases for linked containers in the format container_name:alias.
+
Setting this will force container to be restarted.
+
+
+
+
log_driver
+
string
+
+
Specify the logging driver. Docker uses json-file by default.
log_driver needs to be specified for log_options to take effect, even if using the default json-file driver.
+
+
+
+
mac_address
+
string
+
+
Container MAC address (for example, 92:d0:c6:0a:29:33).
+
+
+
+
memory
+
string
+
+
Memory limit in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
If container_default_behavior is set to compatibility, this option has a default of "0".
+
+
+
+
memory_reservation
+
string
+
+
Memory soft limit in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
+
+
+
memory_swap
+
string
+
+
Total memory limit (memory + swap) in format <number>[<unit>], or the special values unlimited or -1 for unlimited swap usage. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
+
+
+
memory_swappiness
+
integer
+
+
Tune a container’s memory swappiness behavior. Accepts an integer between 0 and 100.
+
If not set, the value will be remain the same if container exists and will be inherited from the host machine if it is (re-)created.
+
+
+
+
mounts
+
list / elements=dictionary
+
+
Specification for mounts to be added to the container. More powerful alternative to volumes.
+
+
+
+
consistency
+
string
+
+
The consistency requirement for the mount.
+
Choices:
+
+
"cached"
+
"consistent"
+
"default"
+
"delegated"
+
+
+
+
+
labels
+
dictionary
+
+
User-defined name and labels for the volume. Only valid for the volume type.
+
+
+
+
no_copy
+
boolean
+
+
False if the volume should be populated with the data from the target. Only valid for the volume type.
+
The default value is false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
propagation
+
string
+
+
Propagation mode. Only valid for the bind type.
+
Choices:
+
+
"private"
+
"rprivate"
+
"shared"
+
"rshared"
+
"slave"
+
"rslave"
+
+
+
+
+
read_only
+
boolean
+
+
Whether the mount should be read-only.
+
Choices:
+
+
false
+
true
+
+
+
+
+
source
+
string
+
+
Mount source.
+
For example, this can be a volume name or a host path.
+
If not supplied when type=volume an anonymous volume will be created.
+
+
+
+
target
+
string / required
+
+
Path inside the container.
+
+
+
+
tmpfs_mode
+
string
+
+
The permission mode for the tmpfs mount.
+
+
+
+
tmpfs_size
+
string
+
+
The size for the tmpfs mount in bytes in format <number>[<unit>].
+
Number is a positive integer. Unit can be one of B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes.
+
+
+
+
type
+
string
+
+
The mount type.
+
Note that npipe is only supported by Docker for Windows.
+
Choices:
+
+
"bind"
+
"npipe"
+
"tmpfs"
+
"volume"← (default)
+
+
+
+
+
volume_driver
+
string
+
+
Specify the volume driver. Only valid for the volume type.
Dictionary of options specific to the chosen volume_driver. See here for details.
+
+
+
+
name
+
string / required
+
+
Assign a name to a new container or match an existing container.
+
When identifying an existing container name may be a name or a long or short container ID.
+
+
+
+
network_mode
+
string
+
+
Connect the container to a network. Choices are bridge, host, none, container:<name|id>, <network_name> or default.
+
Since community.docker 2.0.0, if networks_cli_compatible is true and networks contains at least one network, the default value for network_mode is the name of the first network in the networks list. You can prevent this by explicitly specifying a value for network_mode, like the default value default which will be used by Docker if network_mode is not specified.
+
+
+
+
networks
+
list / elements=dictionary
+
+
List of networks the container belongs to.
+
For examples of the data structure and usage see EXAMPLES below.
+
To remove a container from one or more networks, use networks:strict in the comparisons option.
+
If networks_cli_compatible is set to false, this will not remove the default network if networks is specified. This is different from the behavior of dockerrun.... You need to explicitly use networks:strict in comparisons to enforce the removal of the default network (and all other networks not explicitly mentioned in networks) in that case.
+
+
+
+
aliases
+
list / elements=string
+
+
List of aliases for this container in this network. These names can be used in the network to reach this container.
+
+
+
+
ipv4_address
+
string
+
+
The container’s IPv4 address in this network.
+
+
+
+
ipv6_address
+
string
+
+
The container’s IPv6 address in this network.
+
+
+
+
links
+
list / elements=string
+
+
A list of containers to link to.
+
+
+
+
name
+
string / required
+
+
The network’s name.
+
+
+
+
networks_cli_compatible
+
boolean
+
+
If networks_cli_compatible is set to true (default), this module will behave as dockerrun--network and will not add the default network if networks is specified. If networks is not specified, the default network will be attached.
+
When networks_cli_compatible is set to false and networks are provided to the module via the networks option, the module behaves differently than dockerrun--network: dockerrun--networkother will create a container with network other attached, but the default network not attached. This module with networks: {name: other} will create a container with both default and other attached. If networks:strict or *:strict is set in comparisons, the default network will be removed afterwards.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
oom_killer
+
boolean
+
+
Whether or not to disable OOM Killer for the container.
+
Choices:
+
+
false
+
true
+
+
+
+
+
oom_score_adj
+
integer
+
+
An integer value containing the score given to the container in order to tune OOM killer preferences.
+
+
+
+
output_logs
+
boolean
+
+
If set to true, output of the container command will be printed.
+
Only effective when log_driver is set to json-file, journald, or local.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
paused
+
boolean
+
+
Use with the started state to pause running processes inside the container.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
pid_mode
+
string
+
+
Set the PID namespace mode for the container.
+
+
+
+
pids_limit
+
integer
+
+
Set PIDs limit for the container. It accepts an integer value.
+
Set -1 for unlimited PIDs.
+
+
+
+
platform
+
string
+
added in community.docker 3.0.0
+
+
Platform for the container in the format os[/arch[/variant]].
+
Please note that inspecting the container does not always return the exact platform string used to create the container. This can cause idempotency to break for this module. Use the comparisons option with platform:ignore to prevent accidental recreation of the container due to this.
+
+
+
+
privileged
+
boolean
+
+
Give extended privileges to the container.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
publish_all_ports
+
boolean
+
added in community.docker 1.8.0
+
+
Publish all ports to the host.
+
Any specified port bindings from published_ports will remain intact when true.
+
Choices:
+
+
false
+
true
+
+
+
+
+
+
published_ports
+
aliases: ports
+
list / elements=string
+
+
List of ports to publish from the container to the host.
+
Use docker CLI syntax: 8000, 9000:8000, or 0.0.0.0:9000:8000, where 8000 is a container port, 9000 is a host port, and 0.0.0.0 is a host interface.
+
Port ranges can be used for source and destination ports. If two ranges with different lengths are specified, the shorter range will be used. Since community.general 0.2.0, if the source port range has length 1, the port will not be assigned to the first port of the destination range, but to a free port in that range. This is the same behavior as for docker command line utility.
+
Bind addresses must be either IPv4 or IPv6 addresses. Hostnames are not allowed. This is different from the docker command line utility. Use the dig lookup to resolve hostnames.
+
If networks parameter is provided, will inspect each network to see if there exists a bridge network with optional parameter com.docker.network.bridge.host_binding_ipv4. If such a network is found, then published ports where no host IP address is specified will be bound to the host IP pointed to by com.docker.network.bridge.host_binding_ipv4. Note that the first bridge network with a com.docker.network.bridge.host_binding_ipv4 value encountered in the list of networks is the one that will be used.
+
The value all was allowed in earlier versions of this module. Support for it was removed in community.docker 3.0.0. Use the publish_all_ports option instead.
+
+
+
+
pull
+
boolean
+
+
If true, always pull the latest version of an image. Otherwise, will only pull an image when missing.
+
Note: images are only pulled when specified by name. If the image is specified as a image ID (hash), it cannot be pulled.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
purge_networks
+
boolean
+
+
Remove the container from ALL networks not included in networks parameter.
+
Any default networks such as bridge, if not found in networks, will be removed as well.
+
This option is deprecated since community.docker 3.2.0 and will be removed in community.docker 4.0.0. Use networks:strict in comparisons instead of purge_networks=true and make sure that networks is specified. If you want to remove all networks, specify networks: [].
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
read_only
+
boolean
+
+
Mount the container’s root file system as read-only.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
recreate
+
boolean
+
+
Use with present and started states to force the re-creation of an existing container.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
removal_wait_timeout
+
float
+
+
When removing an existing container, the docker daemon API call exists after the container is scheduled for removal. Removal usually is very fast, but it can happen that during high I/O load, removal can take longer. By default, the module will wait until the container has been removed before trying to (re-)create it, however long this takes.
+
By setting this option, the module will wait at most this many seconds for the container to be removed. If the container is still in the removal phase after this many seconds, the module will fail.
+
+
+
+
restart
+
boolean
+
+
Use with started state to force a matching container to be stopped and restarted.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
restart_policy
+
string
+
+
Container restart policy.
+
Place quotes around no option.
+
Choices:
+
+
"no"
+
"on-failure"
+
"always"
+
"unless-stopped"
+
+
+
+
+
restart_retries
+
integer
+
+
Use with restart policy to control maximum number of restart attempts.
+
+
+
+
runtime
+
string
+
+
Runtime to use for the container.
+
+
+
+
security_opts
+
list / elements=string
+
+
List of security options in the form of "label:user:User".
+
+
+
+
shm_size
+
string
+
+
Size of /dev/shm in format <number>[<unit>]. Number is positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Omitting the unit defaults to bytes. If you omit the size entirely, Docker daemon uses 64M.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
absent - A container matching the specified name will be stopped and removed. Use force_kill to kill the container rather than stopping it. Use keep_volumes to retain anonymous volumes associated with the removed container.
+
present - Asserts the existence of a container matching the name and any provided configuration parameters. If no container matches the name, a container will be created. If a container matches the name but the provided configuration does not match, the container will be updated, if it can be. If it cannot be updated, it will be removed and re-created with the requested config.
+
started - Asserts that the container is first present, and then if the container is not running moves it to a running state. Use restart to force a matching container to be stopped and restarted.
+
stopped - Asserts that the container is first present, and then if the container is running moves it to a stopped state.
+
To control what will be taken into account when comparing configuration, see the comparisons option. To avoid that the image version will be taken into account, you can also use the image:ignore in the comparisons option.
+
Use the recreate option to always force re-creation of a matching container, even if it is running.
+
If the container should be killed instead of stopped in case it needs to be stopped for recreation, or because state is stopped, please use the force_kill option. Use keep_volumes to retain anonymous volumes associated with a removed container.
+
Use keep_volumes to retain anonymous volumes associated with a removed container.
+
Choices:
+
+
"absent"
+
"present"
+
"stopped"
+
"started"← (default)
+
+
+
+
+
stop_signal
+
string
+
+
Override default signal used to stop the container.
+
+
+
+
stop_timeout
+
integer
+
+
Number of seconds to wait for the container to stop before sending SIGKILL. When the container is created by this module, its StopTimeout configuration will be set to this value.
+
When the container is stopped, will be used as a timeout for stopping the container. In case the container has a custom StopTimeout configuration, the behavior depends on the version of the docker daemon. New versions of the docker daemon will always use the container’s configured StopTimeout value if it has been configured.
+
+
+
+
storage_opts
+
dictionary
+
added in community.docker 1.3.0
+
+
Storage driver options for this container as a key-value mapping.
+
+
+
+
sysctls
+
dictionary
+
+
Dictionary of key,value pairs.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
tmpfs
+
list / elements=string
+
+
Mount a tmpfs directory.
+
+
+
+
tty
+
boolean
+
+
Allocate a pseudo-TTY.
+
If container_default_behavior is set to compatibility, this option has a default of false.
+
Choices:
+
+
false
+
true
+
+
+
+
+
ulimits
+
list / elements=string
+
+
List of ulimit options. A ulimit is specified as nofile:262144:262144.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
user
+
string
+
+
Sets the username or UID used and optionally the groupname or GID for the specified command.
+
Can be of the forms user, user:group, uid, uid:gid, user:gid or uid:group.
+
+
+
+
userns_mode
+
string
+
+
Set the user namespace mode for the container. Currently, the only valid value are host and the empty string.
+
+
+
+
uts
+
string
+
+
Set the UTS namespace mode for the container.
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
volume_driver
+
string
+
+
The container volume driver.
+
+
+
+
volumes
+
list / elements=string
+
+
List of volumes to mount within the container.
+
Use docker CLI-style syntax: /host:/container[:mode]
+
Mount modes can be a comma-separated list of various modes such as ro, rw, consistent, delegated, cached, rprivate, private, rshared, shared, rslave, slave, and nocopy. Note that the docker daemon might not support all modes and combinations of such modes.
+
SELinux hosts can additionally use z or Z to use a shared or private label for the volume.
+
Note that Ansible 2.7 and earlier only supported one mode, which had to be one of ro, rw, z, and Z.
+
+
+
+
volumes_from
+
list / elements=string
+
+
List of container names or IDs to get volumes from.
For most config changes, the container needs to be recreated. This means that the existing container has to be destroyed and a new one created. This can cause unexpected data loss and downtime. You can use the comparisons option to prevent this.
+
If the module needs to recreate the container, it will only use the options provided to the module to create the new container (except image). Therefore, always specify all options relevant to the container.
+
When restart is set to true, the module will only restart the container if no config changes are detected.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Create a data container
+community.docker.docker_container:
+name:mydata
+image:busybox
+volumes:
+-/data
+
+-name:Re-create a redis container
+community.docker.docker_container:
+name:myredis
+image:redis
+command:redis-server --appendonly yes
+state:present
+recreate:true
+exposed_ports:
+-6379
+volumes_from:
+-mydata
+
+-name:Restart a container
+community.docker.docker_container:
+name:myapplication
+image:someuser/appimage
+state:started
+restart:true
+links:
+-"myredis:aliasedredis"
+devices:
+-"/dev/sda:/dev/xvda:rwm"
+ports:
+# Publish container port 9000 as host port 8080
+-"8080:9000"
+# Publish container UDP port 9001 as host port 8081 on interface 127.0.0.1
+-"127.0.0.1:8081:9001/udp"
+# Publish container port 9002 as a random host port
+-"9002"
+# Publish container port 9003 as a free host port in range 8000-8100
+# (the host port will be selected by the Docker daemon)
+-"8000-8100:9003"
+# Publish container ports 9010-9020 to host ports 7000-7010
+-"7000-7010:9010-9020"
+env:
+SECRET_KEY:"ssssh"
+# Values which might be parsed as numbers, booleans or other types by the YAML parser need to be quoted
+BOOLEAN_KEY:"yes"
+
+-name:Container present
+community.docker.docker_container:
+name:mycontainer
+state:present
+image:ubuntu:14.04
+command:sleep infinity
+
+-name:Stop a container
+community.docker.docker_container:
+name:mycontainer
+state:stopped
+
+-name:Start 4 load-balanced containers
+community.docker.docker_container:
+name:"container{{item}}"
+recreate:true
+image:someuser/anotherappimage
+command:sleep 1d
+with_sequence:count=4
+
+-name:Remove container
+community.docker.docker_container:
+name:ohno
+state:absent
+
+-name:Syslogging output
+community.docker.docker_container:
+name:myservice
+image:busybox
+log_driver:syslog
+log_options:
+syslog-address:tcp://my-syslog-server:514
+syslog-facility:daemon
+# NOTE: in Docker 1.13+ the "syslog-tag" option was renamed to "tag" for
+# older docker installs, use "syslog-tag" instead
+tag:myservice
+
+-name:Create db container and connect to network
+community.docker.docker_container:
+name:db_test
+image:"postgres:latest"
+networks:
+-name:"{{docker_network_name}}"
+
+-name:Start container, connect to network and link
+community.docker.docker_container:
+name:sleeper
+image:ubuntu:14.04
+networks:
+-name:TestingNet
+ipv4_address:"172.16.1.100"
+aliases:
+-sleepyzz
+links:
+-db_test:db
+-name:TestingNet2
+
+-name:Start a container with a command
+community.docker.docker_container:
+name:sleepy
+image:ubuntu:14.04
+command:["sleep","infinity"]
+
+-name:Add container to networks
+community.docker.docker_container:
+name:sleepy
+networks:
+-name:TestingNet
+ipv4_address:172.16.1.18
+links:
+-sleeper
+-name:TestingNet2
+ipv4_address:172.16.10.20
+
+-name:Update network with aliases
+community.docker.docker_container:
+name:sleepy
+networks:
+-name:TestingNet
+aliases:
+-sleepyz
+-zzzz
+
+-name:Remove container from one network
+community.docker.docker_container:
+name:sleepy
+networks:
+-name:TestingNet2
+comparisons:
+networks:strict
+
+-name:Remove container from all networks
+community.docker.docker_container:
+name:sleepy
+comparisons:
+networks:strict
+
+-name:Start a container and use an env file
+community.docker.docker_container:
+name:agent
+image:jenkinsci/ssh-slave
+env_file:/var/tmp/jenkins/agent.env
+
+-name:Create a container with limited capabilities
+community.docker.docker_container:
+name:sleepy
+image:ubuntu:16.04
+command:sleep infinity
+capabilities:
+-sys_time
+cap_drop:
+-all
+
+-name:Finer container restart/update control
+community.docker.docker_container:
+name:test
+image:ubuntu:18.04
+env:
+arg1:"true"
+arg2:"whatever"
+volumes:
+-/tmp:/tmp
+comparisons:
+image:ignore# do not restart containers with older versions of the image
+env:strict# we want precisely this environment
+volumes:allow_more_present# if there are more volumes, that's ok, as long as `/tmp:/tmp` is there
+
+-name:Finer container restart/update control II
+community.docker.docker_container:
+name:test
+image:ubuntu:18.04
+env:
+arg1:"true"
+arg2:"whatever"
+comparisons:
+'*':ignore# by default, ignore *all* options (including image)
+env:strict# except for environment variables; there, we want to be strict
+
+-name:Start container with healthstatus
+community.docker.docker_container:
+name:nginx-proxy
+image:nginx:1.13
+state:started
+healthcheck:
+# Check if nginx server is healthy by curl'ing the server.
+# If this fails or timeouts, the healthcheck fails.
+test:["CMD","curl","--fail","http://nginx.host.com"]
+interval:1m30s
+timeout:10s
+retries:3
+start_period:30s
+
+-name:Remove healthcheck from container
+community.docker.docker_container:
+name:nginx-proxy
+image:nginx:1.13
+state:started
+healthcheck:
+# The "NONE" check needs to be specified
+test:["NONE"]
+
+-name:Create a tmpfs with a size and mode
+community.docker.docker_container:
+name:tmpfs test
+image:ubuntu:22.04
+state:started
+mounts:
+-type:tmpfs
+target:/cache
+tmpfs_mode:"1700"# only readable to the owner
+tmpfs_size:"16G"
+
+-name:Start container with block device read limit
+community.docker.docker_container:
+name:test
+image:ubuntu:18.04
+state:started
+device_read_bps:
+# Limit read rate for /dev/sda to 20 mebibytes per second
+-path:/dev/sda
+rate:20M
+device_read_iops:
+# Limit read rate for /dev/sdb to 300 IO per second
+-path:/dev/sdb
+rate:300
+
+-name:Start container with GPUs
+community.docker.docker_container:
+name:test
+image:ubuntu:18.04
+state:started
+device_requests:
+-# Add some specific devices to this container
+device_ids:
+-'0'
+-'GPU-3a23c669-1f69-c64e-cf85-44e9b07e7a2a'
+-# Add nVidia GPUs to this container
+driver:nvidia
+count:-1# this means we want all
+capabilities:
+# We have one OR condition: 'gpu' AND 'utility'
+--gpu
+-utility
+# See https://github.com/NVIDIA/nvidia-container-runtime#supported-driver-capabilities
+# for a list of capabilities supported by the nvidia driver
+
+-name:Start container with storage options
+community.docker.docker_container:
+name:test
+image:ubuntu:18.04
+state:started
+storage_opts:
+# Limit root filesystem to 12 MB - note that this requires special storage backends
+# (https://fabianlee.org/2020/01/15/docker-use-overlay2-with-an-xfs-backing-filesystem-to-limit-rootfs-size/)
+size:12m
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this inventory plugin,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_containers.
Add the same groups as the docker inventory script does. These are the following:
+
<containerid>: contains the container of this ID.
+
<containername>: contains the container that has this name.
+
<containershortid>: contains the containers that have this short ID (first 13 letters of ID).
+
image_<imagename>: contains the containers that have the image <imagename>.
+
stack_<stackname>: contains the containers that belong to the stack <stackname>.
+
service_<servicename>: contains the containers that belong to the service <servicename>
+
<docker_host>: contains the containers which belong to the Docker daemon docker_host. Useful if you run this plugin against multiple Docker daemons.
+
running: contains all containers that are running.
+
stopped: contains all containers that are not running.
+
If this is not set to true, you should use keyed groups to add the containers to groups. See the examples for how to do that.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
api_version
+
aliases: docker_api_version
+
string
+
+
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
compose
+
dictionary
+
+
Create vars from jinja2 expressions.
+
Default:{}
+
+
+
+
configure_docker_daemon
+
boolean
+
added in community.docker 1.8.0
+
+
Whether to pass all Docker daemon configuration from the inventory plugin to the connection plugin.
+
Only used when connection_type=docker-api.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
connection_type
+
string
+
+
Which connection type to use the containers.
+
One way to connect to containers is to use SSH (ssh). For this, the options default_ip and private_ssh_port are used. This requires that a SSH daemon is running inside the containers.
When docker-api is used, all Docker daemon configuration values are passed from the inventory plugin to the connection plugin. This can be controlled with configure_docker_daemon.
+
Choices:
+
+
"ssh"
+
"docker-cli"
+
"docker-api"← (default)
+
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
default_ip
+
string
+
+
The IP address to assign to ansible_host when the container’s SSH port is mapped to interface ‘0.0.0.0’.
+
Only used if connection_type is ssh.
+
Default:"127.0.0.1"
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
groups
+
dictionary
+
+
Add hosts to group based on Jinja2 conditionals.
+
Default:{}
+
+
+
+
keyed_groups
+
list / elements=dictionary
+
+
Add hosts to group based on the values of a variable.
+
Default:[]
+
+
+
+
default_value
+
string
+
added in ansible-core 2.12
+
+
The default value when the host variable’s value is an empty string.
+
This option is mutually exclusive with trailing_separator.
+
+
+
+
key
+
string
+
+
The key from input dictionary used to generate groups
+
+
+
+
parent_group
+
string
+
+
parent group for keyed group
+
+
+
+
prefix
+
string
+
+
A keyed group name will start with this prefix
+
Default:""
+
+
+
+
separator
+
string
+
+
separator used to build the keyed group name
+
Default:"_"
+
+
+
+
trailing_separator
+
boolean
+
added in ansible-core 2.12
+
+
Set this option to False to omit the separator after the host variable when the value is an empty string.
+
This option is mutually exclusive with default_value.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
leading_separator
+
boolean
+
added in ansible-core 2.11
+
+
Use in conjunction with keyed_groups.
+
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
+
This is because the default prefix is “” and the default separator is “_”.
+
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
+
If the group name is derived from a mapping the separator is still used to concatenate the items.
+
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
plugin
+
string / required
+
+
The name of this plugin, it should always be set to community.docker.docker_containers for this plugin to recognize it as it’s own.
+
Choices:
+
+
"community.docker.docker_containers"
+
+
+
+
+
private_ssh_port
+
integer
+
+
The port containers use for SSH.
+
Only used if connection_type is ssh.
+
Default:22
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
strict
+
boolean
+
+
If yes make invalid entries a fatal error, otherwise skip and continue.
+
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_extra_vars
+
boolean
+
added in ansible-core 2.11
+
+
Merge extra vars into the available variables for composition (highest precedence).
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
verbose_output
+
boolean
+
+
Toggle to (not) include all available inspection metadata.
+
Note that all top-level keys will be transformed to the format docker_xxx. For example, HostConfig is converted to docker_hostconfig.
+
If this is false, these values can only be used during constructed, groups, and keyed_groups.
+
The docker inventory script always added these variables, so for compatibility set this to true.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
# Minimal example using local Docker daemon
+plugin:community.docker.docker_containers
+docker_host:unix://var/run/docker.sock
+
+# Minimal example using remote Docker daemon
+plugin:community.docker.docker_containers
+docker_host:tcp://my-docker-host:2375
+
+# Example using remote Docker daemon with unverified TLS
+plugin:community.docker.docker_containers
+docker_host:tcp://my-docker-host:2376
+tls:true
+
+# Example using remote Docker daemon with verified TLS and client certificate verification
+plugin:community.docker.docker_containers
+docker_host:tcp://my-docker-host:2376
+validate_certs:true
+ca_cert:/somewhere/ca.pem
+client_key:/somewhere/key.pem
+client_cert:/somewhere/cert.pem
+
+# Example using constructed features to create groups
+plugin:community.docker.docker_containers
+docker_host:tcp://my-docker-host:2375
+strict:false
+keyed_groups:
+# Add containers with primary network foo to a network_foo group
+-prefix:network
+key:'docker_hostconfig.NetworkMode'
+# 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 has not 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)
+
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_host_info.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
containers
+
boolean
+
+
Whether to list containers.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
containers_all
+
boolean
+
added in community.docker 3.4.0
+
+
By default, only running containers are returned.
+
This corresponds to the --all option to dockercontainerlist.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
containers_filters
+
dictionary
+
+
A dictionary of filter values used for selecting containers to list.
+
For example, until:24h.
+
label is a special case of filter which can be a string <key> matching when a label is present, a string <key>=<value> matching when a label has a particular value, or a list of strings <key>/<key>=<value.
Summary information on used disk space by all Docker layers.
+
The output is a sum of images, volumes, containers and build cache.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
images
+
boolean
+
+
Whether to list images.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
images_filters
+
dictionary
+
+
A dictionary of filter values used for selecting images to list.
+
For example, dangling:true.
+
label is a special case of filter which can be a string <key> matching when a label is present, a string <key>=<value> matching when a label has a particular value, or a list of strings <key>/<key>=<value.
A dictionary of filter values used for selecting networks to list.
+
label is a special case of filter which can be a string <key> matching when a label is present, a string <key>=<value> matching when a label has a particular value, or a list of strings <key>/<key>=<value.
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
verbose_output
+
boolean
+
+
When set to true and networks, volumes, images, containers or disk_usage is set to true then output will contain verbose information about objects matching the full output of API method. For details see the documentation of your version of Docker API at https://docs.docker.com/engine/api/.
+
The verbose output in this module contains only subset of information returned by _info module for each type of the objects.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
volumes
+
boolean
+
+
Whether to list volumes.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
volumes_filters
+
dictionary
+
+
A dictionary of filter values used for selecting volumes to list.
+
label is a special case of filter which can be a string <key> matching when a label is present, a string <key>=<value> matching when a label has a particular value, or a list of strings <key>/<key>=<value.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Get info on docker host
+community.docker.docker_host_info:
+register:result
+
+-name:Get info on docker host and list images
+community.docker.docker_host_info:
+images:true
+register:result
+
+-name:Get info on docker host and list images matching the filter
+community.docker.docker_host_info:
+images:true
+images_filters:
+label:"mylabel"
+register:result
+
+-name:Get info on docker host and verbose list images
+community.docker.docker_host_info:
+images:true
+verbose_output:true
+register:result
+
+-name:Get info on docker host and used disk space
+community.docker.docker_host_info:
+disk_usage:true
+register:result
+
+-name:Get info on docker host and list containers matching the filter
+community.docker.docker_host_info:
+containers:true
+containers_filters:
+label:
+-key1=value1
+-key2=value2
+register:result
+
+-ansible.builtin.debug:
+var:result.host_info
+
Common return values are documented here, the following are the fields unique to this module:
+
+
+
Key
+
Description
+
+
+
+
+
can_talk_to_docker
+
boolean
+
+
Will be true if the module can talk to the docker daemon.
+
Returned: both on success and on error
+
+
+
+
containers
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each container. Keys matches the dockercontainerls output unless verbose_output=true. See description for verbose_output.
+
Returned: When containers is true
+
+
+
+
disk_usage
+
dictionary
+
+
Information on summary disk usage by images, containers and volumes on docker host unless verbose_output=true. See description for verbose_output.
+
Returned: When disk_usage is true
+
+
+
+
host_info
+
dictionary
+
+
Facts representing the basic state of the docker host. Matches the dockersysteminfo output.
+
Returned: always
+
+
+
+
images
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each image. Keys matches the dockerimagels output unless verbose_output=true. See description for verbose_output.
+
Returned: When images is true
+
+
+
+
networks
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each network. Keys matches the dockernetworkls output unless verbose_output=true. See description for verbose_output.
+
Returned: When networks is true
+
+
+
+
volumes
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each volume. Keys matches the dockervolumels output unless verbose_output=true. See description for verbose_output.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_image_info.
Provide one or more image names, and the module will inspect each, returning an array of inspection results.
+
If an image does not exist locally, it will not appear in the results. If you want to check whether an image exists locally, you can call the module with the image name, then check whether the result list is empty (image does not exist) or has one element (the image exists locally).
+
The module will not attempt to pull images from registries. Use community.docker.docker_image with source set to pull to ensure an image is pulled.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
name
+
list / elements=string
+
+
An image name or a list of image names. Name format will be name[:tag] or repository/name[:tag], where tag is optional. If a tag is not provided, latest will be used. Instead of image names, also image IDs can be used.
+
If no name is provided, a list of all images will be returned.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
This module was called docker_image_facts before Ansible 2.8. The usage did not change.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_image_load.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
path
+
path / required
+
+
The path to the .tar archive to load Docker image(s) from.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Load all image(s) from the given tar file
+community.docker.docker_image_load:
+path:/path/to/images.tar
+register:result
+
+-name:Print the loaded image names
+ansible.builtin.debug:
+msg:"Loadedthefollowingimages:{{result.image_names|join(', ')}}"
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_image.
Build, load or pull an image, making the image available for creating containers. Also supports tagging an image, pushing an image, and archiving an image to a .tar file.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
archive_path
+
path
+
+
Use with state present to archive an image to a .tar file.
+
+
+
+
build
+
dictionary
+
+
Specifies options used for building images.
+
+
+
+
args
+
dictionary
+
+
Provide a dictionary of key:value build arguments that map to Dockerfile ARG directive.
+
Docker expects the value to be a string. For convenience any non-string values will be converted to strings.
+
+
+
+
cache_from
+
list / elements=string
+
+
List of image names to consider as cache source.
+
+
+
+
container_limits
+
dictionary
+
+
A dictionary of limits applied to each container created by the build process.
+
+
+
+
cpusetcpus
+
string
+
+
CPUs in which to allow execution.
+
For example, 0-3 or 0,1.
+
+
+
+
cpushares
+
integer
+
+
CPU shares (relative weight).
+
+
+
+
memory
+
integer
+
+
Set memory limit for build.
+
+
+
+
memswap
+
integer
+
+
Total memory (memory + swap).
+
Use -1 to disable swap.
+
+
+
+
dockerfile
+
string
+
+
Use with state present and source build to provide an alternate name for the Dockerfile to use when building an image.
+
This can also include a relative path (relative to path).
+
+
+
+
etc_hosts
+
dictionary
+
+
Extra hosts to add to /etc/hosts in building containers, as a mapping of hostname to IP address.
+
+
+
+
http_timeout
+
integer
+
+
Timeout for HTTP requests during the image build operation. Provide a positive integer value for the number of seconds.
+
+
+
+
network
+
string
+
+
The network to use for RUN build instructions.
+
+
+
+
nocache
+
boolean
+
+
Do not use cache when building an image.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
path
+
path / required
+
+
Use with state ‘present’ to build an image. Will be the path to a directory containing the context and Dockerfile for building an image.
+
+
+
+
platform
+
string
+
added in community.docker 1.1.0
+
+
Platform in the format os[/arch[/variant]].
+
+
+
+
pull
+
boolean
+
+
When building an image downloads any updates to the FROM image in Dockerfile.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
rm
+
boolean
+
+
Remove intermediate containers after build.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
target
+
string
+
+
When building an image specifies an intermediate build stage by name as a final stage for the resulting image.
+
+
+
+
use_config_proxy
+
boolean
+
+
If set to true and a proxy configuration is specified in the docker client configuration (by default $HOME/.docker/config.json), the corresponding environment variables will be set in the container being built.
+
Choices:
+
+
false
+
true
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
force_absent
+
boolean
+
+
Use with state absent to un-tag and remove all images matching the specified name.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
force_source
+
boolean
+
+
Use with state present to build, load or pull an image (depending on the value of the source option) when the image already exists.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
force_tag
+
boolean
+
+
Use with state present to force tagging an image.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
load_path
+
path
+
+
Use with state present to load an image from a .tar file.
+
Set source to load if you want to load the image.
+
+
+
+
name
+
string / required
+
+
Image name. Name format will be one of: name, repository/name, registry_server:port/name. When pushing or pulling an image the name can optionally include the tag by appending :tag_name.
+
Note that image IDs (hashes) are only supported for state=absent, for state=present with source=load, and for state=present with source=local.
+
+
+
+
pull
+
dictionary
+
added in community.docker 1.3.0
+
+
Specifies options used for pulling images.
+
+
+
+
platform
+
string
+
+
When pulling an image, ask for this specific platform.
+
Note that this value is not used to determine whether the image needs to be pulled. This might change in the future in a minor release, though.
+
+
+
+
push
+
boolean
+
+
Push the image to the registry. Specify the registry as part of the name or repository parameter.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
repository
+
string
+
+
Use with state present to tag the image.
+
Expects format repository:tag. If no tag is provided, will use the value of the tag parameter or latest.
+
If push=true, repository must either include a registry, or will be assumed to belong to the default registry (Docker Hub).
+
+
+
+
source
+
string
+
+
Determines where the module will try to retrieve the image from.
+
Use build to build the image from a Dockerfile. build.path must be specified when this value is used.
+
Use load to load the image from a .tar file. load_path must be specified when this value is used.
+
Use pull to pull the image from a registry.
+
Use local to make sure that the image is already available on the local docker daemon. This means that the module does not try to build, pull or load the image.
+
Choices:
+
+
"build"
+
"load"
+
"pull"
+
"local"
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
Make assertions about the state of an image.
+
When absent an image will be removed. Use the force option to un-tag and remove all images matching the provided name.
+
When present check if an image exists using the provided name and tag. If the image is not found or the force option is used, the image will either be pulled, built or loaded, depending on the source option.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
tag
+
string
+
+
Used to select an image when pulling. Will be added to the image when pushing, tagging or building. Defaults to latest.
+
If name parameter format is name:tag, then tag value from name will take precedence.
+
Default:"latest"
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Building images is done using Docker daemon’s API. It is not possible to use BuildKit / buildx this way.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Pull an image
+community.docker.docker_image:
+name:pacur/centos-7
+source:pull
+# Select platform for pulling. If not specified, will pull whatever docker prefers.
+pull:
+platform:amd64
+
+-name:Tag and push to docker hub
+community.docker.docker_image:
+name:pacur/centos-7:56
+repository:dcoppenhagan/myimage:7.56
+push:true
+source:local
+
+-name:Tag and push to local registry
+community.docker.docker_image:
+# Image will be centos:7
+name:centos
+# Will be pushed to localhost:5000/centos:7
+repository:localhost:5000/centos
+tag:7
+push:true
+source:local
+
+-name:Add tag latest to image
+community.docker.docker_image:
+name:myimage:7.1.2
+repository:myimage:latest
+# As 'latest' usually already is present, we need to enable overwriting of existing tags:
+force_tag:true
+source:local
+
+-name:Remove image
+community.docker.docker_image:
+state:absent
+name:registry.ansible.com/chouseknecht/sinatra
+tag:v1
+
+-name:Build an image and push it to a private repo
+community.docker.docker_image:
+build:
+path:./sinatra
+name:registry.ansible.com/chouseknecht/sinatra
+tag:v1
+push:true
+source:build
+
+-name:Archive image
+community.docker.docker_image:
+name:registry.ansible.com/chouseknecht/sinatra
+tag:v1
+archive_path:my_sinatra.tar
+source:local
+
+-name:Load image from archive and push to a private registry
+community.docker.docker_image:
+name:localhost:5000/myimages/sinatra
+tag:v1
+push:true
+load_path:my_sinatra.tar
+source:load
+
+-name:Build image and with build args
+community.docker.docker_image:
+name:myimage
+build:
+path:/path/to/build/dir
+args:
+log_volume:/var/log/myapp
+listen_port:8080
+source:build
+
+-name:Build image using cache source
+community.docker.docker_image:
+name:myimage:latest
+build:
+path:/path/to/build/dir
+# Use as cache source for building myimage
+cache_from:
+-nginx:latest
+-alpine:3.8
+source:build
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_login.
Provides functionality similar to the dockerlogin command.
+
Authenticate with a docker registry and add the credentials to your local Docker config file respectively the credentials store associated to the registry. Adding the credentials to the config files resp. the credential store allows future connections to the registry using tools such as Ansible’s Docker modules, the Docker CLI and Docker SDK for Python without needing to provide credentials.
+
Running in check mode will perform the authentication without updating the config file.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
config_path
+
aliases: dockercfg_path
+
path
+
+
Custom path to the Docker CLI configuration file.
+
Default:"~/.docker/config.json"
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
password
+
string
+
+
The plaintext password for the registry account.
+
Required when state is present.
+
+
+
+
+
reauthorize
+
aliases: reauth
+
boolean
+
+
Refresh existing authentication found in the configuration file.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
+
registry_url
+
aliases: registry, url
+
string
+
+
The registry URL.
+
Default:"https://index.docker.io/v1/"
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
This controls the current state of the user. present will login in a user, absent will log them out.
+
To logout you only need the registry server, which defaults to DockerHub.
+
Before 2.1 you could ONLY log in.
+
Docker does not support ‘logout’ with a custom config file.
+
Choices:
+
+
"present"← (default)
+
"absent"
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
username
+
string
+
+
The username for the registry account.
+
Required when state is present.
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
-name:Log into DockerHub
+community.docker.docker_login:
+username:docker
+password:rekcod
+
+-name:Log into private registry and force re-authorization
+community.docker.docker_login:
+registry_url:your.private.registry.io
+username:yourself
+password:secrets3
+reauthorize:true
+
+-name:Log into DockerHub using a custom config file
+community.docker.docker_login:
+username:docker
+password:rekcod
+config_path:/tmp/.mydockercfg
+
+-name:Log out of DockerHub
+community.docker.docker_login:
+state:absent
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this inventory plugin,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_machine.
Whether docker daemon connection environment variables should be fetched, and how to behave if they cannot be fetched.
+
With require and require-silently, fetch them and skip any host for which they cannot be fetched. A warning will be issued for any skipped host if the choice is require.
+
With optional and optional-silently, fetch them and not skip hosts for which they cannot be fetched. A warning will be issued for hosts where they cannot be fetched if the choice is optional.
+
With skip, do not attempt to fetch the docker daemon connection environment variables.
+
If fetched successfully, the variables will be prefixed with dm_ and stored as host variables.
+
Choices:
+
+
"require"← (default)
+
"require-silently"
+
"optional"
+
"optional-silently"
+
"skip"
+
+
+
+
+
groups
+
dictionary
+
+
Add hosts to group based on Jinja2 conditionals.
+
Default:{}
+
+
+
+
keyed_groups
+
list / elements=dictionary
+
+
Add hosts to group based on the values of a variable.
+
Default:[]
+
+
+
+
default_value
+
string
+
added in ansible-core 2.12
+
+
The default value when the host variable’s value is an empty string.
+
This option is mutually exclusive with trailing_separator.
+
+
+
+
key
+
string
+
+
The key from input dictionary used to generate groups
+
+
+
+
parent_group
+
string
+
+
parent group for keyed group
+
+
+
+
prefix
+
string
+
+
A keyed group name will start with this prefix
+
Default:""
+
+
+
+
separator
+
string
+
+
separator used to build the keyed group name
+
Default:"_"
+
+
+
+
trailing_separator
+
boolean
+
added in ansible-core 2.12
+
+
Set this option to False to omit the separator after the host variable when the value is an empty string.
+
This option is mutually exclusive with default_value.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
leading_separator
+
boolean
+
added in ansible-core 2.11
+
+
Use in conjunction with keyed_groups.
+
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
+
This is because the default prefix is “” and the default separator is “_”.
+
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
+
If the group name is derived from a mapping the separator is still used to concatenate the items.
+
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
plugin
+
string / required
+
+
token that ensures this is a source file for the docker_machine plugin.
+
Choices:
+
+
"docker_machine"
+
"community.docker.docker_machine"
+
+
+
+
+
running_required
+
boolean
+
+
When true, hosts which Docker Machine indicates are in a state other than running will be skipped.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
strict
+
boolean
+
+
If yes make invalid entries a fatal error, otherwise skip and continue.
+
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
use_extra_vars
+
boolean
+
added in ansible-core 2.11
+
+
Merge extra vars into the available variables for composition (highest precedence).
# Minimal example
+plugin:community.docker.docker_machine
+
+# Example using constructed features to create a group per Docker Machine driver
+# (https://docs.docker.com/machine/drivers/), for example:
+# $ docker-machine create --driver digitalocean ... mymachine
+# $ ansible-inventory -i ./path/to/docker-machine.yml --host=mymachine
+# {
+# ...
+# "digitalocean": {
+# "hosts": [
+# "mymachine"
+# ]
+# ...
+# }
+strict:false
+keyed_groups:
+-separator:''
+key:docker_machine_node_attributes.DriverName
+
+# Example grouping hosts by Digital Machine tag
+strict:false
+keyed_groups:
+-prefix:tag
+key:'dm_tags'
+
+# Example using compose to override the default SSH behaviour of asking the user to accept the remote host key
+compose:
+ansible_ssh_common_args:'"-oStrictHostKeyChecking=accept-new"'
+
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_network_info.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
name
+
string / required
+
+
The name of the network to inspect.
+
When identifying an existing network name may be a name or a long or short network ID.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_network.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
appends
+
aliases: incremental
+
boolean
+
+
By default the connected list is canonical, meaning containers not on the list are removed from the network.
+
Use appends to leave existing containers connected.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
attachable
+
boolean
+
+
If enabled, and the network is in the global scope, non-service containers on worker nodes will be able to connect to the network.
+
Choices:
+
+
false
+
true
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
connected
+
aliases: containers
+
list / elements=string
+
+
List of container names or container IDs to connect to a network.
+
Please note that the module only makes sure that these containers are connected to the network, but does not care about connection options. If you rely on specific IP addresses etc., use the community.docker.docker_container module to ensure your containers are correctly connected to this network.
+
Default:[]
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
driver
+
string
+
+
Specify the type of network. Docker provides bridge and overlay drivers, but 3rd party drivers can also be used.
+
Default:"bridge"
+
+
+
+
driver_options
+
dictionary
+
+
Dictionary of network settings. Consult docker docs for valid options and values.
+
Default:{}
+
+
+
+
enable_ipv6
+
boolean
+
+
Enable IPv6 networking.
+
Choices:
+
+
false
+
true
+
+
+
+
+
force
+
boolean
+
+
With state absent forces disconnecting all containers from the network prior to deleting the network. With state present will disconnect all containers, delete the network and re-create the network.
+
This option is required if you have changed the IPAM or driver options and want an existing network to be updated to use the new options.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
internal
+
boolean
+
+
Restrict external access to the network.
+
Choices:
+
+
false
+
true
+
+
+
+
+
ipam_config
+
list / elements=dictionary
+
+
List of IPAM config blocks. Consult Docker docs for valid options and values. Note that iprange is spelled differently here (we use the notation from the Docker SDK for Python).
+
+
+
+
aux_addresses
+
dictionary
+
+
Auxiliary IP addresses used by Network driver, as a mapping from hostname to IP.
+
+
+
+
gateway
+
string
+
+
IP gateway address.
+
+
+
+
iprange
+
string
+
+
IP address range in CIDR notation.
+
+
+
+
subnet
+
string
+
+
IP subset in CIDR notation.
+
+
+
+
ipam_driver
+
string
+
+
Specify an IPAM driver.
+
+
+
+
ipam_driver_options
+
dictionary
+
+
Dictionary of IPAM driver options.
+
+
+
+
labels
+
dictionary
+
+
Dictionary of labels.
+
Default:{}
+
+
+
+
+
name
+
aliases: network_name
+
string / required
+
+
Name of the network to operate on.
+
+
+
+
scope
+
string
+
+
Specify the network’s scope.
+
Choices:
+
+
"local"
+
"global"
+
"swarm"
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
absent deletes the network. If a network has connected containers, it cannot be deleted. Use the force option to disconnect all containers and delete the network.
+
present creates the network, if it does not already exist with the specified parameters, and connects the list of containers provided via the connected parameter. Containers not on the list will be disconnected. An empty list will leave no containers connected to the network. Use the appends option to leave existing containers connected. Use the force options to force re-creation of the network.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
When network options are changed, the module disconnects all containers from the network, deletes the network, and re-creates the network. It does not try to reconnect containers, except the ones listed in (connected, and even for these, it does not consider specific connection options like fixed IP addresses or MAC addresses. If you need more control over how the containers are connected to the network, loop the community.docker.docker_container module to loop over your containers to make sure they are connected properly.
+
The module does not support Docker Swarm. This means that it will not try to disconnect or reconnect services. If services are connected to the network, deleting the network will fail. When network options are changed, the network has to be deleted and recreated, so this will fail as well.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_node_info.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
name
+
list / elements=string
+
+
The name of the node to inspect.
+
The list of nodes names to inspect.
+
If empty then return information of all nodes in Swarm cluster.
+
When identifying the node use either the hostname of the node (as registered in Swarm) or node ID.
+
If self is true then this parameter is ignored.
+
+
+
+
self
+
boolean
+
+
If true, queries the node (that is, the docker daemon) the module communicates with.
+
If true then name is ignored.
+
If false then query depends on name presence and value.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
-name:Get info on all nodes
+community.docker.docker_node_info:
+register:result
+
+-name:Get info on node
+community.docker.docker_node_info:
+name:mynode
+register:result
+
+-name:Get info on list of nodes
+community.docker.docker_node_info:
+name:
+-mynode1
+-mynode2
+register:result
+
+-name:Get info on host if it is Swarm Manager
+community.docker.docker_node_info:
+self:true
+register:result
+
Common return values are documented here, the following are the fields unique to this module:
+
+
+
Key
+
Description
+
+
+
+
+
nodes
+
list / elements=dictionary
+
+
Facts representing the current state of the nodes. Matches the dockernodeinspect output.
+
Can contain multiple entries if more than one node provided in name, or name is not provided.
+
If name contains a list of nodes, the output will provide information on all nodes registered at the swarm, including nodes that left the swarm but have not been removed from the cluster on swarm managers and nodes that are unreachable.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_node.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
availability
+
string
+
+
Node availability to assign. If not provided then node availability remains unchanged.
+
Choices:
+
+
"active"
+
"pause"
+
"drain"
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
hostname
+
string / required
+
+
The hostname or ID of node as registered in Swarm.
+
If more than one node is registered using the same hostname the ID must be used, otherwise module will fail.
+
+
+
+
labels
+
dictionary
+
+
User-defined key/value metadata that will be assigned as node attribute.
+
Label operations in this module apply to the docker swarm node specified by hostname. Use community.docker.docker_swarm module to add/modify/remove swarm cluster labels.
+
The actual state of labels assigned to the node when module completes its work depends on labels_state and labels_to_remove parameters values. See description below.
+
+
+
+
labels_state
+
string
+
+
It defines the operation on the labels assigned to node and labels specified in labels option.
+
Set to merge to combine labels provided in labels with those already assigned to the node. If no labels are assigned then it will add listed labels. For labels that are already assigned to the node, it will update their values. The labels not specified in labels will remain unchanged. If labels is empty then no changes will be made.
+
Set to replace to replace all assigned labels with provided ones. If labels is empty then all labels assigned to the node will be removed.
+
Choices:
+
+
"merge"← (default)
+
"replace"
+
+
+
+
+
labels_to_remove
+
list / elements=string
+
+
List of labels that will be removed from the node configuration. The list has to contain only label names, not their values.
+
If the label provided on the list is not assigned to the node, the entry is ignored.
+
If the label is both on the labels_to_remove and labels, then value provided in labels remains assigned to the node.
+
If labels_state is replace and labels is not provided or empty then all labels assigned to node are removed and labels_to_remove is ignored.
+
+
+
+
role
+
string
+
+
Node role to assign. If not provided then node role remains unchanged.
+
Choices:
+
+
"manager"
+
"worker"
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_plugin.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
enable_timeout
+
integer
+
+
Timeout in seconds.
+
Default:0
+
+
+
+
force_remove
+
boolean
+
+
Remove even if the plugin is enabled.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
plugin_name
+
string / required
+
+
Name of the plugin to operate on.
+
+
+
+
plugin_options
+
dictionary
+
+
Dictionary of plugin settings.
+
Default:{}
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
absent remove the plugin.
+
present install the plugin, if it does not already exist.
+
enable enable the plugin.
+
disable disable the plugin.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
"enable"
+
"disable"
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_prune.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
builder_cache
+
boolean
+
+
Whether to prune the builder cache.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
containers
+
boolean
+
+
Whether to prune containers.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
containers_filters
+
dictionary
+
+
A dictionary of filter values used for selecting containers to delete.
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
images
+
boolean
+
+
Whether to prune images.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
images_filters
+
dictionary
+
+
A dictionary of filter values used for selecting images to delete.
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
volumes
+
boolean
+
+
Whether to prune volumes.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
volumes_filters
+
dictionary
+
+
A dictionary of filter values used for selecting volumes to delete.
The module always returned changed=false before community.docker 3.5.1.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_secret.
Create and remove Docker secrets in a Swarm environment. Similar to dockersecretcreate and dockersecretrm.
+
Adds to the metadata of new secrets ansible_key, an encrypted hash representation of the data, which is then used in future runs to test if a secret has changed. If ansible_key is not present, then a secret will not be updated unless the force option is set.
+
Updates to secrets are performed by removing the secret and creating it again.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). This module does *not* work with docker-py.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
data
+
string
+
+
The value of the secret.
+
Mutually exclusive with data_src. One of data and data_src is required if state=present.
+
+
+
+
data_is_b64
+
boolean
+
+
If set to true, the data is assumed to be Base64 encoded and will be decoded before being used.
+
To use binary data, it is better to keep it Base64 encoded and let it be decoded by this option.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
data_src
+
path
+
added in community.docker 1.10.0
+
+
The file on the target from which to read the secret.
+
Mutually exclusive with data. One of data and data_src is required if state=present.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
force
+
boolean
+
+
Use with state present to always remove and recreate an existing secret.
+
If true, an existing secret will be replaced, even if it has not changed.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
labels
+
dictionary
+
+
A map of key:value meta data, where both key and value are expected to be strings.
+
If new meta data is provided, or existing meta data is modified, the secret will be updated by removing it and creating it again.
+
+
+
+
name
+
string / required
+
+
The name of the secret.
+
+
+
+
rolling_versions
+
boolean
+
added in community.docker 2.2.0
+
+
If set to true, secrets are created with an increasing version number appended to their name.
+
Adds a label containing the version number to the managed secrets with the name ansible_version.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
Set to present, if the secret should exist, and absent, if it should not.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
versions_to_keep
+
integer
+
added in community.docker 2.2.0
+
+
When using rolling_versions, the number of old versions of the secret to keep.
+
Extraneous old secrets are deleted after the new one is created.
+
Set to -1 to keep everything or to 0 or 1 to keep only the current one.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
-name:Create secret foo (from a file on the control machine)
+community.docker.docker_secret:
+name:foo
+# If the file is JSON or binary, Ansible might modify it (because
+# it is first decoded and later re-encoded). Base64-encoding the
+# file directly after reading it prevents this to happen.
+data:"{{lookup('file','/path/to/secret/file')|b64encode}}"
+data_is_b64:true
+state:present
+
+-name:Create secret foo (from a file on the target machine)
+community.docker.docker_secret:
+name:foo
+data_src:/path/to/secret/file
+state:present
+
+-name:Change the secret data
+community.docker.docker_secret:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+state:present
+
+-name:Add a new label
+community.docker.docker_secret:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+# Adding a new label will cause a remove/create of the secret
+two:'2'
+state:present
+
+-name:No change
+community.docker.docker_secret:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:baz
+one:'1'
+# Even though 'two' is missing, there is no change to the existing secret
+state:present
+
+-name:Update an existing label
+community.docker.docker_secret:
+name:foo
+data:Goodnight everyone!
+labels:
+bar:monkey# Changing a label will cause a remove/create of the secret
+one:'1'
+state:present
+
+-name:Force the removal/creation of the secret
+community.docker.docker_secret:
+name:foo
+data:Goodnight everyone!
+force:true
+state:present
+
+-name:Remove secret foo
+community.docker.docker_secret:
+name:foo
+state:absent
+
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_stack.
If >0 and state is absent the module will retry up to absent_retries times to delete the stack until all the resources have been effectively deleted. If the last try still reports the stack as not completely removed the module will fail.
+
Default:0
+
+
+
+
absent_retries_interval
+
integer
+
+
Interval in seconds between consecutive absent_retries.
+
Default:1
+
+
+
+
compose
+
list / elements=any
+
+
List of compose definitions. Any element may be a string referring to the path of the compose file on the target host or the YAML contents of a compose file nested as dictionary.
+
Default:[]
+
+
+
+
name
+
string / required
+
+
Stack name
+
+
+
+
prune
+
boolean
+
+
If true will add the --prune option to the dockerstackdeploy command. This will have docker remove the services not present in the current stack definition.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
resolve_image
+
string
+
+
If set will add the --resolve-image option to the dockerstackdeploy command. This will have docker query the registry to resolve image digest and supported platforms. If not set, docker use “always” by default.
+
Choices:
+
+
"always"
+
"changed"
+
"never"
+
+
+
+
+
state
+
string
+
+
Service state.
+
Choices:
+
+
"present"← (default)
+
"absent"
+
+
+
+
+
with_registry_auth
+
boolean
+
+
If true will add the --with-registry-auth option to the dockerstackdeploy command. This will have docker send registry authentication details to Swarm agents.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_swarm_info.
Returns lists of swarm objects names for the services - nodes, services, tasks.
+
The output differs depending on API version available on docker host.
+
Must be run on Swarm Manager node; otherwise module fails with error message. It does return boolean flags in on both error and success which indicate whether the docker daemon can be communicated with, whether it is in Swarm mode, and whether it is a Swarm Manager node.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
nodes
+
boolean
+
+
Whether to list swarm nodes.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
nodes_filters
+
dictionary
+
+
A dictionary of filter values used for selecting nodes to list.
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
unlock_key
+
boolean
+
+
Whether to retrieve the swarm unlock key.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
verbose_output
+
boolean
+
+
When set to true and nodes, services or tasks is set to true, then the module output will contain verbose information about objects matching the full output of API method.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
-name:Get info on Docker Swarm
+community.docker.docker_swarm_info:
+ignore_errors:true
+register:result
+
+-name:Inform about basic flags
+ansible.builtin.debug:
+msg:|
+Was able to talk to docker daemon: {{result.can_talk_to_docker}}
+Docker in Swarm mode: {{result.docker_swarm_active}}
+This is a Manager node: {{result.docker_swarm_manager}}
+
+-block:
+
+-name:Get info on Docker Swarm and list of registered nodes
+community.docker.docker_swarm_info:
+nodes:true
+register:result
+
+-name:Get info on Docker Swarm and extended list of registered nodes
+community.docker.docker_swarm_info:
+nodes:true
+verbose_output:true
+register:result
+
+-name:Get info on Docker Swarm and filtered list of registered nodes
+community.docker.docker_swarm_info:
+nodes:true
+nodes_filters:
+name:mynode
+register:result
+
+-ansible.builtin.debug:
+var:result.swarm_facts
+
+-name:Get the swarm unlock key
+community.docker.docker_swarm_info:
+unlock_key:true
+register:result
+
+-ansible.builtin.debug:
+var:result.swarm_unlock_key
+
Common return values are documented here, the following are the fields unique to this module:
+
+
+
Key
+
Description
+
+
+
+
+
can_talk_to_docker
+
boolean
+
+
Will be true if the module can talk to the docker daemon.
+
Returned: both on success and on error
+
+
+
+
docker_swarm_active
+
boolean
+
+
Will be true if the module can talk to the docker daemon, and the docker daemon is in Swarm mode.
+
Returned: both on success and on error
+
+
+
+
docker_swarm_manager
+
boolean
+
+
Will be true if the module can talk to the docker daemon, the docker daemon is in Swarm mode, and the current node is a manager node.
+
Only if this one is true, the module will not fail.
+
Returned: both on success and on error
+
+
+
+
nodes
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each volume. Keys matches the dockernodels output unless verbose_output=true. See description for verbose_output.
+
Returned: When nodes is true
+
+
+
+
services
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each volume. Keys matches the dockerservicels output unless verbose_output=true. See description for verbose_output.
+
Returned: When services is true
+
+
+
+
swarm_facts
+
dictionary
+
+
Facts representing the basic state of the docker Swarm cluster.
+
Contains tokens to connect to the Swarm
+
Returned: always
+
+
+
+
swarm_unlock_key
+
string
+
+
Contains the key needed to unlock the swarm.
+
Returned: When unlock_key is true.
+
+
+
+
tasks
+
list / elements=dictionary
+
+
List of dict objects containing the basic information about each volume. Keys matches the dockerserviceps output unless verbose_output=true. See description for verbose_output.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this inventory plugin,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_swarm.
Uses a YAML configuration file docker_swarm.[yml|yaml].
+
The plugin returns following groups of swarm nodes: all - all hosts; workers - all worker nodes; managers - all manager nodes; leader - the swarm leader node; nonleaders - all nodes except the swarm leader.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python.
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
+
+
+
compose
+
dictionary
+
+
Create vars from jinja2 expressions.
+
Default:{}
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string / required
+
+
Socket of a Docker swarm manager node (tcp, unix).
+
Use unix://var/run/docker.sock to connect via local socket.
+
+
+
+
groups
+
dictionary
+
+
Add hosts to group based on Jinja2 conditionals.
+
Default:{}
+
+
+
+
include_host_uri
+
boolean
+
+
Toggle to return the additional attribute ansible_host_uri which contains the URI of the swarm leader in format of tcp://172.16.0.1:2376. This value may be used without additional modification as value of option docker_host in Docker Swarm modules when connecting via API. The port always defaults to 2376.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
include_host_uri_port
+
integer
+
+
Override the detected port number included in ansible_host_uri
+
+
+
+
keyed_groups
+
list / elements=dictionary
+
+
Add hosts to group based on the values of a variable.
+
Default:[]
+
+
+
+
default_value
+
string
+
added in ansible-core 2.12
+
+
The default value when the host variable’s value is an empty string.
+
This option is mutually exclusive with trailing_separator.
+
+
+
+
key
+
string
+
+
The key from input dictionary used to generate groups
+
+
+
+
parent_group
+
string
+
+
parent group for keyed group
+
+
+
+
prefix
+
string
+
+
A keyed group name will start with this prefix
+
Default:""
+
+
+
+
separator
+
string
+
+
separator used to build the keyed group name
+
Default:"_"
+
+
+
+
trailing_separator
+
boolean
+
added in ansible-core 2.12
+
+
Set this option to False to omit the separator after the host variable when the value is an empty string.
+
This option is mutually exclusive with default_value.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
leading_separator
+
boolean
+
added in ansible-core 2.11
+
+
Use in conjunction with keyed_groups.
+
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
+
This is because the default prefix is “” and the default separator is “_”.
+
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
+
If the group name is derived from a mapping the separator is still used to concatenate the items.
+
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
+
Choices:
+
+
false
+
true← (default)
+
+
+
+
+
plugin
+
string / required
+
+
The name of this plugin, it should always be set to community.docker.docker_swarm for this plugin to recognize it as it’s own.
+
Choices:
+
+
"docker_swarm"
+
"community.docker.docker_swarm"
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
+
+
+
strict
+
boolean
+
+
If yes make invalid entries a fatal error, otherwise skip and continue.
+
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
timeout
+
aliases: time_out
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Connect using TLS without verifying the authenticity of the Docker host server.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker host server, provide the expected name of the server.
+
+
+
+
use_extra_vars
+
boolean
+
added in ansible-core 2.11
+
+
Merge extra vars into the available variables for composition (highest precedence).
# Minimal example using local docker
+plugin:community.docker.docker_swarm
+docker_host:unix://var/run/docker.sock
+
+# Minimal example using remote docker
+plugin:community.docker.docker_swarm
+docker_host:tcp://my-docker-host:2375
+
+# Example using remote docker with unverified TLS
+plugin:community.docker.docker_swarm
+docker_host:tcp://my-docker-host:2376
+tls:true
+
+# Example using remote docker with verified TLS and client certificate verification
+plugin:community.docker.docker_swarm
+docker_host:tcp://my-docker-host:2376
+validate_certs:true
+ca_cert:/somewhere/ca.pem
+client_key:/somewhere/key.pem
+client_cert:/somewhere/cert.pem
+
+# Example using constructed features to create groups and set ansible_host
+plugin:community.docker.docker_swarm
+docker_host:tcp://my-docker-host:2375
+strict:false
+keyed_groups:
+# add for example x86_64 hosts to an arch_x86_64 group
+-prefix:arch
+key:'Description.Platform.Architecture'
+# add for example linux hosts to an os_linux group
+-prefix:os
+key:'Description.Platform.OS'
+# create a group per node label
+# for exomple a node labeled w/ "production" ends up in group "label_production"
+# hint: labels containing special characters will be converted to safe names
+-key:'Spec.Labels'
+prefix:label
+
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_swarm.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
Externally reachable address advertised to other nodes.
+
This can either be an address/port combination in the form 192.168.1.1:4567, or an interface followed by a port number, like eth0:4567.
+
If the port number is omitted, the port number from the listen address is used.
+
If advertise_addr is not specified, it will be automatically detected when possible.
+
Only used when swarm is initialised or joined. Because of this it’s not considered for idempotency checking.
+
+
+
+
+
api_version
+
aliases: docker_api_version
+
string
+
+
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
autolock_managers
+
boolean
+
+
If set, generate a key and use it to lock data stored on the managers.
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
ca_force_rotate
+
integer
+
+
An integer whose purpose is to force swarm to generate a new signing CA certificate and key, if none have been specified.
+
Docker default value is 0.
+
Requires API version >= 1.30.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
data_path_addr
+
string
+
added in community.docker 2.5.0
+
+
Address or interface to use for data path traffic.
+
This can either be an address in the form 192.168.1.1, or an interface, like eth0.
+
Only used when swarm is initialised or joined. Because of this it is not considered for idempotency checking.
+
+
+
+
data_path_port
+
integer
+
added in community.docker 3.1.0
+
+
Port to use for data path traffic.
+
This needs to be a port number like 9789.
+
Only used when swarm is initialised. Because of this it is not considered for idempotency checking.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
default_addr_pool
+
list / elements=string
+
+
Default address pool in CIDR format.
+
Only used when swarm is initialised. Because of this it’s not considered for idempotency checking.
+
Requires API version >= 1.39.
+
+
+
+
dispatcher_heartbeat_period
+
integer
+
+
The delay for an agent to send a heartbeat to the dispatcher.
+
Docker default value is 5s.
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
election_tick
+
integer
+
+
Amount of ticks (in seconds) needed without a leader to trigger a new election.
+
Docker default value is 10s.
+
+
+
+
force
+
boolean
+
+
Use with state present to force creating a new Swarm, even if already part of one.
+
Use with state absent to Leave the swarm even if this node is a manager.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
heartbeat_tick
+
integer
+
+
Amount of ticks (in seconds) between each heartbeat.
+
Docker default value is 1s.
+
+
+
+
join_token
+
string
+
+
Swarm token used to join a swarm cluster.
+
Used with state=join.
+
If this value is specified, the corresponding value in the return values will be censored by Ansible. This is a side-effect of this value not being logged.
+
+
+
+
keep_old_snapshots
+
integer
+
+
Number of snapshots to keep beyond the current snapshot.
+
Docker default value is 0.
+
+
+
+
labels
+
dictionary
+
+
User-defined key/value metadata.
+
Label operations in this module apply to the docker swarm cluster. Use community.docker.docker_node module to add/modify/remove swarm node labels.
+
Requires API version >= 1.32.
+
+
+
+
listen_addr
+
string
+
+
Listen address used for inter-manager communication.
+
This can either be an address/port combination in the form 192.168.1.1:4567, or an interface followed by a port number, like eth0:4567.
+
If the port number is omitted, the default swarm listening port is used.
+
Only used when swarm is initialised or joined. Because of this it’s not considered for idempotency checking.
+
Default:"0.0.0.0:2377"
+
+
+
+
log_entries_for_slow_followers
+
integer
+
+
Number of log entries to keep around to sync up slow followers after a snapshot is created.
+
+
+
+
name
+
string
+
+
The name of the swarm.
+
+
+
+
node_cert_expiry
+
integer
+
+
Automatic expiry for nodes certificates.
+
Docker default value is 3months.
+
+
+
+
node_id
+
string
+
+
Swarm id of the node to remove.
+
Used with state=remove.
+
+
+
+
remote_addrs
+
list / elements=string
+
+
Remote address of one or more manager nodes of an existing Swarm to connect to.
+
Used with state=join.
+
+
+
+
rotate_manager_token
+
boolean
+
+
Rotate the manager join token.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
rotate_worker_token
+
boolean
+
+
Rotate the worker join token.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
signing_ca_cert
+
string
+
+
The desired signing CA certificate for all swarm node TLS leaf certificates, in PEM format.
+
This must not be a path to a certificate, but the contents of the certificate.
+
Requires API version >= 1.30.
+
+
+
+
signing_ca_key
+
string
+
+
The desired signing CA key for all swarm node TLS leaf certificates, in PEM format.
+
This must not be a path to a key, but the contents of the key.
+
Requires API version >= 1.30.
+
+
+
+
snapshot_interval
+
integer
+
+
Number of logs entries between snapshot.
+
Docker default value is 10000.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
Set to present, to create/update a new cluster.
+
Set to join, to join an existing cluster.
+
Set to absent, to leave an existing cluster.
+
Set to remove, to remove an absent node from the cluster. Note that removing requires Docker SDK for Python >= 2.4.0.
Only used when swarm is initialised. Because of this it’s not considered for idempotency checking.
+
Requires API version >= 1.39.
+
+
+
+
task_history_retention_limit
+
integer
+
+
Maximum number of tasks history stored.
+
Docker default value is 5.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
-name:Init a new swarm with default parameters
+community.docker.docker_swarm:
+state:present
+
+-name:Update swarm configuration
+community.docker.docker_swarm:
+state:present
+election_tick:5
+
+-name:Add nodes
+community.docker.docker_swarm:
+state:join
+advertise_addr:192.168.1.2
+join_token:SWMTKN-1--xxxxx
+remote_addrs:['192.168.1.1:2377']
+
+-name:Leave swarm for a node
+community.docker.docker_swarm:
+state:absent
+
+-name:Remove a swarm manager
+community.docker.docker_swarm:
+state:absent
+force:true
+
+-name:Remove node from swarm
+community.docker.docker_swarm:
+state:remove
+node_id:mynode
+
+-name:Init a new swarm with different data path interface
+community.docker.docker_swarm:
+state:present
+advertise_addr:eth0
+data_path_addr:ens10
+
+-name:Init a new swarm with a different data path port
+community.docker.docker_swarm:
+state:present
+data_path_port:9789
+
Common return values are documented here, the following are the fields unique to this module:
+
+
+
Key
+
Description
+
+
+
+
+
actions
+
list / elements=string
+
+
Provides the actions done on the swarm.
+
Returned: when action failed.
+
Sample:["Thisclusterisalreadyaswarmcluster"]
+
+
+
+
swarm_facts
+
dictionary
+
+
Informations about swarm.
+
Returned: success
+
+
+
+
JoinTokens
+
dictionary
+
+
Tokens to connect to the Swarm.
+
Returned: success
+
+
+
+
Manager
+
string
+
+
Token to join the cluster as a new *manager* node.
+
Note: if this value has been specified as join_token, the value here will not be the token, but VALUE_SPECIFIED_IN_NO_LOG_PARAMETER. If you pass join_token, make sure your playbook/role does not depend on this return value!
+
Returned: success
+
Sample:"SWMTKN-1--xxxxx"
+
+
+
+
Worker
+
string
+
+
Token to join the cluster as a new *worker* node.
+
Note: if this value has been specified as join_token, the value here will not be the token, but VALUE_SPECIFIED_IN_NO_LOG_PARAMETER. If you pass join_token, make sure your playbook/role does not depend on this return value!
+
Returned: success
+
Sample:"SWMTKN-1--xxxxx"
+
+
+
+
UnlockKey
+
string
+
+
The swarm unlock-key if autolock_managers is true.
+
Returned: on success if autolock_managers is true and swarm is initialised, or if autolock_managers has changed.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_swarm_service_info.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). Note that both modules should *not* be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
name
+
string / required
+
+
The name of the service to inspect.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_swarm_service.
The below requirements are needed on the host that executes this module.
+
+
Docker API >= 1.25
+
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). This module does *not* work with docker-py.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
args
+
list / elements=string
+
+
List arguments to be passed to the container.
+
Corresponds to the ARG parameter of dockerservicecreate.
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
cap_add
+
list / elements=string
+
added in community.docker 2.2.0
+
+
List of capabilities to add to the container.
+
Requires API version >= 1.41.
+
+
+
+
cap_drop
+
list / elements=string
+
added in community.docker 2.2.0
+
+
List of capabilities to drop from the container.
+
Requires API version >= 1.41.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
command
+
any
+
+
Command to execute when the container starts.
+
A command may be either a string or a list or a list of strings.
+
Corresponds to the COMMAND parameter of dockerservicecreate.
+
+
+
+
configs
+
list / elements=dictionary
+
+
List of dictionaries describing the service configs.
+
Corresponds to the --config option of dockerservicecreate.
+
Requires API version >= 1.30.
+
+
+
+
config_id
+
string
+
+
Config’s ID.
+
+
+
+
config_name
+
string / required
+
+
Config’s name as defined at its creation.
+
+
+
+
filename
+
string
+
+
Name of the file containing the config. Defaults to the config_name if not specified.
+
+
+
+
gid
+
string
+
+
GID of the config file’s group.
+
+
+
+
mode
+
integer
+
+
File access mode inside the container. Must be an octal number (like 0644 or 0444).
+
+
+
+
uid
+
string
+
+
UID of the config file’s owner.
+
+
+
+
container_labels
+
dictionary
+
+
Dictionary of key value pairs.
+
Corresponds to the --container-label option of dockerservicecreate.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
dns
+
list / elements=string
+
+
List of custom DNS servers.
+
Corresponds to the --dns option of dockerservicecreate.
+
+
+
+
dns_options
+
list / elements=string
+
+
List of custom DNS options.
+
Corresponds to the --dns-option option of dockerservicecreate.
+
+
+
+
dns_search
+
list / elements=string
+
+
List of custom DNS search domains.
+
Corresponds to the --dns-search option of dockerservicecreate.
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
endpoint_mode
+
string
+
+
Service endpoint mode.
+
Corresponds to the --endpoint-mode option of dockerservicecreate.
+
Choices:
+
+
"vip"
+
"dnsrr"
+
+
+
+
+
env
+
any
+
+
List or dictionary of the service environment variables.
+
If passed a list each items need to be in the format of KEY=VALUE.
+
If passed a dictionary values which might be parsed as numbers, booleans or other types by the YAML parser must be quoted (for example "true") in order to avoid data loss.
+
Corresponds to the --env option of dockerservicecreate.
+
+
+
+
env_files
+
list / elements=path
+
+
List of paths to files, present on the target, containing environment variables FOO=BAR.
+
The order of the list is significant in determining the value assigned to a variable that shows up more than once.
+
If variable also present in env, then env value will override.
+
+
+
+
force_update
+
boolean
+
+
Force update even if no changes require it.
+
Corresponds to the --force option of dockerserviceupdate.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
groups
+
list / elements=string
+
+
List of additional group names and/or IDs that the container process will run as.
+
Corresponds to the --group option of dockerserviceupdate.
+
+
+
+
healthcheck
+
dictionary
+
+
Configure a check that is run to determine whether or not containers for this service are “healthy”. See the docs for the HEALTHCHECK Dockerfile instruction for details on how healthchecks work.
+
interval, timeout and start_period are specified as durations. They accept duration as a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
+
+
+
interval
+
string
+
+
Time between running the check.
+
+
+
+
retries
+
integer
+
+
Consecutive failures needed to report unhealthy. It accept integer value.
+
+
+
+
start_period
+
string
+
+
Start period for the container to initialize before starting health-retries countdown.
+
+
+
+
test
+
any
+
+
Command to run to check health.
+
Must be either a string or a list. If it is a list, the first item must be one of NONE, CMD or CMD-SHELL.
+
+
+
+
timeout
+
string
+
+
Maximum time to allow one check to run.
+
+
+
+
hostname
+
string
+
+
Container hostname.
+
Corresponds to the --hostname option of dockerservicecreate.
+
+
+
+
hosts
+
dictionary
+
+
Dict of host-to-IP mappings, where each host name is a key in the dictionary. Each host name will be added to the container’s /etc/hosts file.
+
Corresponds to the --host option of dockerservicecreate.
+
+
+
+
image
+
string
+
+
Service image path and tag.
+
Corresponds to the IMAGE parameter of dockerservicecreate.
+
+
+
+
init
+
boolean
+
+
Use an init inside each service container to forward signals and reap processes.
+
Corresponds to the --init option of dockerservicecreate.
+
Requires API version >= 1.37.
+
Choices:
+
+
false
+
true
+
+
+
+
+
labels
+
dictionary
+
+
Dictionary of key value pairs.
+
Corresponds to the --label option of dockerservicecreate.
+
+
+
+
limits
+
dictionary
+
+
Configures service resource limits.
+
+
+
+
cpus
+
float
+
+
Service CPU limit. 0 equals no limit.
+
Corresponds to the --limit-cpu option of dockerservicecreate.
+
+
+
+
memory
+
string
+
+
Service memory limit in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
0 equals no limit.
+
Omitting the unit defaults to bytes.
+
Corresponds to the --limit-memory option of dockerservicecreate.
+
+
+
+
logging
+
dictionary
+
+
Logging configuration for the service.
+
+
+
+
driver
+
string
+
+
Configure the logging driver for a service.
+
Corresponds to the --log-driver option of dockerservicecreate.
+
+
+
+
options
+
dictionary
+
+
Options for service logging driver.
+
Corresponds to the --log-opt option of dockerservicecreate.
+
+
+
+
mode
+
string
+
+
Service replication mode.
+
Service will be removed and recreated when changed.
+
Corresponds to the --mode option of dockerservicecreate.
+
Choices:
+
+
"replicated"← (default)
+
"global"
+
+
+
+
+
mounts
+
list / elements=dictionary
+
+
List of dictionaries describing the service mounts.
+
Corresponds to the --mount option of dockerservicecreate.
+
+
+
+
driver_config
+
dictionary
+
+
Volume driver configuration.
+
Can only be used when type is volume.
+
+
+
+
name
+
string
+
+
Name of the volume-driver plugin to use for the volume.
+
+
+
+
options
+
dictionary
+
+
Options as key-value pairs to pass to the driver for this volume.
+
+
+
+
labels
+
dictionary
+
+
Volume labels to apply.
+
+
+
+
no_copy
+
boolean
+
+
Disable copying of data from a container when a volume is created.
+
Can only be used when type is volume.
+
Choices:
+
+
false
+
true
+
+
+
+
+
propagation
+
string
+
+
The propagation mode to use.
+
Can only be used when type is bind.
+
Choices:
+
+
"shared"
+
"slave"
+
"private"
+
"rshared"
+
"rslave"
+
"rprivate"
+
+
+
+
+
readonly
+
boolean
+
+
Whether the mount should be read-only.
+
Choices:
+
+
false
+
true
+
+
+
+
+
source
+
string
+
+
Mount source (for example a volume name or a host path).
+
Must be specified if type is not tmpfs.
+
+
+
+
target
+
string / required
+
+
Container path.
+
+
+
+
tmpfs_mode
+
integer
+
+
File mode of the tmpfs in octal.
+
Can only be used when type is tmpfs.
+
+
+
+
tmpfs_size
+
string
+
+
Size of the tmpfs mount in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
Can only be used when type is tmpfs.
+
+
+
+
type
+
string
+
+
The mount type.
+
Note that npipe is only supported by Docker for Windows. Also note that npipe was added in Ansible 2.9.
+
Choices:
+
+
"bind"← (default)
+
"volume"
+
"tmpfs"
+
"npipe"
+
+
+
+
+
name
+
string / required
+
+
Service name.
+
Corresponds to the --name option of dockerservicecreate.
+
+
+
+
networks
+
list / elements=any
+
+
List of the service networks names or dictionaries.
+
When passed dictionaries valid sub-options are name, which is required, and aliases and options.
+
Prior to API version 1.29, updating and removing networks is not supported. If changes are made the service will then be removed and recreated.
+
Corresponds to the --network option of dockerservicecreate.
+
+
+
+
placement
+
dictionary
+
+
Configures service placement preferences and constraints.
+
+
+
+
constraints
+
list / elements=string
+
+
List of the service constraints.
+
Corresponds to the --constraint option of dockerservicecreate.
+
+
+
+
preferences
+
list / elements=dictionary
+
+
List of the placement preferences as key value pairs.
+
Corresponds to the --placement-pref option of dockerservicecreate.
+
Requires API version >= 1.27.
+
+
+
+
replicas_max_per_node
+
integer
+
added in community.docker 1.3.0
+
+
Maximum number of tasks per node.
+
Corresponds to the --replicas_max_per_node option of dockerservicecreate.
+
Requires API version >= 1.40
+
+
+
+
publish
+
list / elements=dictionary
+
+
List of dictionaries describing the service published ports.
+
Corresponds to the --publish option of dockerservicecreate.
+
+
+
+
mode
+
string
+
+
What publish mode to use.
+
Requires API version >= 1.32.
+
Choices:
+
+
"ingress"
+
"host"
+
+
+
+
+
protocol
+
string
+
+
What protocol to use.
+
Choices:
+
+
"tcp"← (default)
+
"udp"
+
+
+
+
+
published_port
+
integer
+
+
The port to make externally available.
+
+
+
+
target_port
+
integer / required
+
+
The port inside the container to expose.
+
+
+
+
read_only
+
boolean
+
+
Mount the containers root filesystem as read only.
+
Corresponds to the --read-only option of dockerservicecreate.
+
Choices:
+
+
false
+
true
+
+
+
+
+
replicas
+
integer
+
+
Number of containers instantiated in the service. Valid only if mode is replicated.
+
If set to -1, and service is not present, service replicas will be set to 1.
+
If set to -1, and service is present, service replicas will be unchanged.
+
Corresponds to the --replicas option of dockerservicecreate.
+
Default:-1
+
+
+
+
reservations
+
dictionary
+
+
Configures service resource reservations.
+
+
+
+
cpus
+
float
+
+
Service CPU reservation. 0 equals no reservation.
+
Corresponds to the --reserve-cpu option of dockerservicecreate.
+
+
+
+
memory
+
string
+
+
Service memory reservation in format <number>[<unit>]. Number is a positive integer. Unit can be B (byte), K (kibibyte, 1024B), M (mebibyte), G (gibibyte), T (tebibyte), or P (pebibyte).
+
0 equals no reservation.
+
Omitting the unit defaults to bytes.
+
Corresponds to the --reserve-memory option of dockerservicecreate.
+
+
+
+
resolve_image
+
boolean
+
+
If the current image digest should be resolved from registry and updated if changed.
+
Requires API version >= 1.30.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
restart_config
+
dictionary
+
+
Configures if and how to restart containers when they exit.
+
+
+
+
condition
+
string
+
+
Restart condition of the service.
+
Corresponds to the --restart-condition option of dockerservicecreate.
+
Choices:
+
+
"none"
+
"on-failure"
+
"any"
+
+
+
+
+
delay
+
string
+
+
Delay between restarts.
+
Accepts a a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --restart-delay option of dockerservicecreate.
+
+
+
+
max_attempts
+
integer
+
+
Maximum number of service restarts.
+
Corresponds to the --restart-condition option of dockerservicecreate.
+
+
+
+
window
+
string
+
+
Restart policy evaluation window.
+
Accepts a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --restart-window option of dockerservicecreate.
+
+
+
+
rollback_config
+
dictionary
+
+
Configures how the service should be rolled back in case of a failing update.
+
+
+
+
delay
+
string
+
+
Delay between task rollbacks.
+
Accepts a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --rollback-delay option of dockerservicecreate.
+
Requires API version >= 1.28.
+
+
+
+
failure_action
+
string
+
+
Action to take in case of rollback failure.
+
Corresponds to the --rollback-failure-action option of dockerservicecreate.
+
Requires API version >= 1.28.
+
Choices:
+
+
"continue"
+
"pause"
+
+
+
+
+
max_failure_ratio
+
float
+
+
Fraction of tasks that may fail during a rollback.
+
Corresponds to the --rollback-max-failure-ratio option of dockerservicecreate.
+
Requires API version >= 1.28.
+
+
+
+
monitor
+
string
+
+
Duration after each task rollback to monitor for failure.
+
Accepts a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --rollback-monitor option of dockerservicecreate.
+
Requires API version >= 1.28.
+
+
+
+
order
+
string
+
+
Specifies the order of operations during rollbacks.
+
Corresponds to the --rollback-order option of dockerservicecreate.
+
Requires API version >= 1.29.
+
+
+
+
parallelism
+
integer
+
+
The number of containers to rollback at a time. If set to 0, all containers rollback simultaneously.
+
Corresponds to the --rollback-parallelism option of dockerservicecreate.
+
Requires API version >= 1.28.
+
+
+
+
secrets
+
list / elements=dictionary
+
+
List of dictionaries describing the service secrets.
+
Corresponds to the --secret option of dockerservicecreate.
+
+
+
+
filename
+
string
+
+
Name of the file containing the secret. Defaults to the secret_name if not specified.
+
Corresponds to the target key of dockerservicecreate--secret.
+
+
+
+
gid
+
string
+
+
GID of the secret file’s group.
+
+
+
+
mode
+
integer
+
+
File access mode inside the container. Must be an octal number (like 0644 or 0444).
+
+
+
+
secret_id
+
string
+
+
Secret’s ID.
+
+
+
+
secret_name
+
string / required
+
+
Secret’s name as defined at its creation.
+
+
+
+
uid
+
string
+
+
UID of the secret file’s owner.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
absent - A service matching the specified name will be removed and have its tasks stopped.
+
present - Asserts the existence of a service matching the name and provided configuration parameters. Unspecified configuration parameters will be set to docker defaults.
+
Choices:
+
+
"present"← (default)
+
"absent"
+
+
+
+
+
stop_grace_period
+
string
+
+
Time to wait before force killing a container.
+
Accepts a duration as a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --stop-grace-period option of dockerservicecreate.
+
+
+
+
stop_signal
+
string
+
+
Override default signal used to stop the container.
+
Corresponds to the --stop-signal option of dockerservicecreate.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
tty
+
boolean
+
+
Allocate a pseudo-TTY.
+
Corresponds to the --tty option of dockerservicecreate.
+
Choices:
+
+
false
+
true
+
+
+
+
+
update_config
+
dictionary
+
+
Configures how the service should be updated. Useful for configuring rolling updates.
+
+
+
+
delay
+
string
+
+
Rolling update delay.
+
Accepts a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --update-delay option of dockerservicecreate.
+
+
+
+
failure_action
+
string
+
+
Action to take in case of container failure.
+
Corresponds to the --update-failure-action option of dockerservicecreate.
+
Usage of rollback requires API version >= 1.29.
+
Choices:
+
+
"continue"
+
"pause"
+
"rollback"
+
+
+
+
+
max_failure_ratio
+
float
+
+
Fraction of tasks that may fail during an update before the failure action is invoked.
+
Corresponds to the --update-max-failure-ratio option of dockerservicecreate.
+
+
+
+
monitor
+
string
+
+
Time to monitor updated tasks for failures.
+
Accepts a string in a format that look like: 5h34m56s, 1m30s etc. The supported units are us, ms, s, m and h.
+
Corresponds to the --update-monitor option of dockerservicecreate.
+
+
+
+
order
+
string
+
+
Specifies the order of operations when rolling out an updated task.
+
Corresponds to the --update-order option of dockerservicecreate.
+
Requires API version >= 1.29.
+
+
+
+
parallelism
+
integer
+
+
Rolling update parallelism.
+
Corresponds to the --update-parallelism option of dockerservicecreate.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Requires Docker SDK for Python 4.4.0 or newer.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
user
+
string
+
+
Sets the username or UID used for the specified command.
+
Before Ansible 2.8, the default value for this option was root.
+
The default has been removed so that the user defined in the image is used if no user is specified here.
+
Corresponds to the --user option of dockerservicecreate.
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
working_dir
+
string
+
+
Path to the working directory.
+
Corresponds to the --workdir option of dockerservicecreate.
Images will only resolve to the latest digest when using Docker API >= 1.30 and Docker SDK for Python >= 3.2.0. When using older versions use force_update:true to trigger the swarm to resolve a new image.
+
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing docker[tls] with ansible.builtin.pip.
+
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use $HOME/.docker/config.json if the DOCKER_CONFIG environment variable is not specified, and use $DOCKER_CONFIG/config.json otherwise.
Common return values are documented here, the following are the fields unique to this module:
+
+
+
Key
+
Description
+
+
+
+
+
changes
+
list / elements=string
+
+
List of changed service attributes if a service has been altered, [] otherwise.
+
Returned: always
+
Sample:["container_labels","replicas"]
+
+
+
+
rebuilt
+
boolean
+
+
True if the service has been recreated (removed and created)
+
Returned: always
+
Sample:true
+
+
+
+
swarm_service
+
dictionary
+
+
Dictionary of variables representing the current state of the service. Matches the module parameters format.
+
Note that facts are not part of registered vars but accessible directly.
+
Note that before Ansible 2.7.9, the return variable was documented as ansible_swarm_service, while the module actually returned a variable called ansible_docker_service. The variable was renamed to swarm_service in both code and documentation for Ansible 2.7.9 and Ansible 2.8.0. In Ansible 2.7.x, the old name ansible_docker_service can still be used.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_volume_info.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
+
name
+
aliases: volume_name
+
string / required
+
+
Name of the volume to inspect.
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
To install it, use: ansible-galaxycollectioninstallcommunity.docker.
+You need further requirements to be able to use this module,
+see Requirements for details.
+
To use it in a playbook, specify: community.docker.docker_volume.
The version of the Docker API running on the Docker Host.
+
Defaults to the latest version of the API supported by this collection and the docker daemon.
+
If the value is not specified in the task, the value of environment variable DOCKER_API_VERSION will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"auto"
+
+
+
+
+
+
ca_cert
+
aliases: tls_ca_cert, cacert_path
+
path
+
+
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file ca.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_cert
+
aliases: tls_client_cert, cert_path
+
path
+
+
Path to the client’s TLS certificate file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file cert.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
+
+
client_key
+
aliases: tls_client_key, key_path
+
path
+
+
Path to the client’s TLS key file.
+
If the value is not specified in the task and the environment variable DOCKER_CERT_PATH is set, the file key.pem from the directory specified in the environment variable DOCKER_CERT_PATH will be used.
+
+
+
+
debug
+
boolean
+
+
Debug mode
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
docker_host
+
aliases: docker_url
+
string
+
+
The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, tcp://192.0.2.23:2376. If TLS is used to encrypt the connection, the module will automatically replace tcp in the connection URL with https.
+
If the value is not specified in the task, the value of environment variable DOCKER_HOST will be used instead. If the environment variable is not set, the default value will be used.
+
Default:"unix://var/run/docker.sock"
+
+
+
+
driver
+
string
+
+
Specify the type of volume. Docker provides the local driver, but 3rd party drivers can also be used.
Dictionary of label key/values to set for the volume
+
+
+
+
recreate
+
string
+
+
Controls when a volume will be recreated when state is present. Please note that recreating an existing volume will cause any data in the existing volume to be lost! The volume will be deleted and a new volume with the same name will be created.
+
The value always forces the volume to be always recreated.
+
The value never makes sure the volume will not be recreated.
+
The value options-changed makes sure the volume will be recreated if the volume already exist and the driver, driver options or labels differ.
+
Choices:
+
+
"always"
+
"never"← (default)
+
"options-changed"
+
+
+
+
+
ssl_version
+
string
+
+
Provide a valid SSL version number. Default value determined by ssl.py module.
+
If the value is not specified in the task, the value of environment variable DOCKER_SSL_VERSION will be used instead.
+
+
+
+
state
+
string
+
+
absent deletes the volume.
+
present creates the volume, if it does not already exist.
+
Choices:
+
+
"absent"
+
"present"← (default)
+
+
+
+
+
timeout
+
integer
+
+
The maximum amount of time in seconds to wait on a response from the API.
+
If the value is not specified in the task, the value of environment variable DOCKER_TIMEOUT will be used instead. If the environment variable is not set, the default value will be used.
+
Default:60
+
+
+
+
tls
+
boolean
+
+
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if validate_certs is set to true as well, it will take precedence.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS will be used instead. If the environment variable is not set, the default value will be used.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
tls_hostname
+
string
+
+
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_HOSTNAME will be used instead. If the environment variable is not set, the default value will be used.
+
Note that this option had a default value localhost in older versions. It was removed in community.docker 3.0.0.
+
+
+
+
use_ssh_client
+
boolean
+
added in community.docker 1.5.0
+
+
For SSH transports, use the ssh CLI tool instead of paramiko.
+
Choices:
+
+
false← (default)
+
true
+
+
+
+
+
+
validate_certs
+
aliases: tls_verify
+
boolean
+
+
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
+
If the value is not specified in the task, the value of environment variable DOCKER_TLS_VERIFY will be used instead. If the environment variable is not set, the default value will be used.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define DOCKER_HOST, DOCKER_TLS_HOSTNAME, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_SSL_VERSION, DOCKER_TLS, DOCKER_TLS_VERIFY and DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
+
This module does not use the Docker SDK for Python to communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection.
Most of the modules and plugins in community.docker require the Docker SDK for Python. The SDK needs to be installed on the machines where the modules and plugins are executed, and for the Python version(s) with which the modules and plugins are executed. You can use the community.general.python_requirements_info module to make sure that the Docker SDK for Python is installed on the correct machine and for the Python version used by Ansible.
+
Note that plugins (inventory plugins and connection plugins) are always executed in the context of Ansible itself. If you use a plugin that requires the Docker SDK for Python, you need to install it on the machine running ansible or ansible-playbook and for the same Python interpreter used by Ansible. To see which Python is used, run ansible--version.
+
You can install the Docker SDK for Python for Python 3.6 or later as follows:
+
$pipinstalldocker
+
+
+
For Python 2.7, you need to use a version between 2.0.0 and 4.4.4 since the Python package for Docker removed support for Python 2.7 on 5.0.0. You can install the specific version of the Docker SDK for Python as follows:
+
$pipinstall'docker==4.4.4'
+
+
+
Note that the Docker SDK for Python was called docker-py on PyPi before version 2.0.0. Please avoid installing this really old version, and make sure to not install both docker and docker-py. Installing both will result in a broken installation. If this happens, Ansible will detect it and inform you about it. If that happens, you must uninstall both and reinstall the correct version. If in doubt, always install docker and never docker-py.
You can connect to a local or remote API using parameters passed to each task or by setting environment variables. The order of precedence is command line parameters and then environment variables. If neither a command line option nor an environment variable is found, Ansible uses the default value provided under Parameters.
Most plugins and modules can be configured by the following parameters:
+
+
+
docker_host
The URL or Unix socket path used to connect to the Docker API. Defaults to unix://var/run/docker.sock. To connect to a remote host, provide the TCP connection string (for example: tcp://192.0.2.23:2376). If TLS is used to encrypt the connection to the API, then the module will automatically replace ‘tcp’ in the connection URL with ‘https’.
+
+
api_version
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported by the Docker SDK for Python installed.
+
+
timeout
The maximum amount of time in seconds to wait on a response from the API. Defaults to 60 seconds.
+
+
tls
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Defaults to false.
+
+
validate_certs
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. Default is false.
+
+
cacert_path
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
+
+
cert_path
Path to the client’s TLS certificate file.
+
+
key_path
Path to the client’s TLS key file.
+
+
tls_hostname
When verifying the authenticity of the Docker Host server, provide the expected name of the server. Defaults to localhost.
+
+
ssl_version
Provide a valid SSL version number. The default value is determined by the Docker SDK for Python.
You can also control how the plugins and modules connect to the Docker API by setting the following environment variables.
+
For plugins, they have to be set for the environment Ansible itself runs in. For modules, they have to be set for the environment the modules are executed in. For modules running on remote machines, the environment variables have to be set on that machine for the user used to execute the modules with.
+
+
+
DOCKER_HOST
The URL or Unix socket path used to connect to the Docker API.
+
+
DOCKER_API_VERSION
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported
+by Docker SDK for Python.
+
+
DOCKER_TIMEOUT
The maximum amount of time in seconds to wait on a response from the API.
+
+
DOCKER_CERT_PATH
Path to the directory containing the client certificate, client key and CA certificate.
+
+
DOCKER_SSL_VERSION
Provide a valid SSL version number.
+
+
DOCKER_TLS
Secure the connection to the API by using TLS without verifying the authenticity of the Docker Host.
+
+
DOCKER_TLS_VERIFY
Secure the connection to the API by using TLS and verify the authenticity of the Docker Host.
The docker inventory script is deprecated. Please use the inventory plugin instead. The inventory plugin has several compatibility options. If you need to collect Docker containers from multiple Docker daemons, you need to add every Docker daemon as an individual inventory source.
+
+
docker_host_info module
The community.docker.docker_host_info module allows you to retrieve information on a Docker daemon, such as all containers, images, volumes, networks and so on.
+
+
docker_login module
The community.docker.docker_login module allows you to log in and out of a remote registry, such as Docker Hub or a private registry. It provides similar functionality to the dockerlogin and dockerlogout CLI commands.
+
+
docker_prune module
The community.docker.docker_prune module allows you to prune no longer needed containers, images, volumes and so on. It provides similar functionality to the dockerprune CLI command.
The community.docker.docker_container module manages the container lifecycle by providing the ability to create, update, stop, start and destroy a Docker container.
The community.docker.docker_compose module
+allows you to use your existing Docker compose files to orchestrate containers on a single Docker daemon or on Swarm.
+Supports compose versions 1 and 2.
+
Next to Docker SDK for Python, you need to install docker-compose on the remote machines to use the module.
The community.docker.docker_swarm module allows you to globally configure Docker Swarm manager nodes to join and leave swarms, and to change the Docker Swarm configuration.
Still using Dockerfile to build images? Check out ansible-bender, and start building images from your Ansible playbooks.
+
Use Ansible Operator to launch your docker-compose file on OpenShift. Go from an app on your laptop to a fully scalable app in the cloud with Kubernetes in just a few moments.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pr/613/environment_variables.html b/pr/613/environment_variables.html
new file mode 100644
index 00000000..c778012a
--- /dev/null
+++ b/pr/613/environment_variables.html
@@ -0,0 +1,205 @@
+
+
+
+
+
+
+ Index of all Collection Environment Variables — Community.Docker Collection documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The following index documents all environment variables declared by plugins in collections.
+Environment variables used by the ansible-core configuration are documented in Ansible Configuration Settings.
This connection plugin allows Ansible, running in a privileged container, to execute tasks on the container host instead of in the container itself.
+
This is useful for running Ansible in a pull model, while still keeping the Ansible control node containerized.
+
It relies on having privileged access to run nsenter in the host’s PID namespace, allowing it to enter the namespaces of the provided PID (default PID 1, or init/systemd).
The remote user is ignored; this plugin always runs as root.
+
This plugin requires the Ansible controller container to be launched in the following way: (1) The container image contains the nsenter program; (2) The container is launched in privileged mode; (3) The container is launched in the host’s PID namespace (--pidhost).
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.