| 1 |
# Copyright (c) Ansible Project |
| 2 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time. |
| 6 |
# Do not use this from other collections or standalone plugins/modules! |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
|
| 11 |
class ModuleDocFragment: |
| 12 |
|
| 13 |
# Docker doc fragment |
| 14 |
DOCUMENTATION = r""" |
| 15 |
options: |
| 16 |
docker_host: |
| 17 |
description: |
| 18 |
- The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection |
| 19 |
string. For example, V(tcp://192.0.2.23:2376). If TLS is used to encrypt the connection, the module will automatically |
| 20 |
replace C(tcp) in the connection URL with C(https). |
| 21 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_HOST) will be used instead. |
| 22 |
If the environment variable is not set, the default value will be used. |
| 23 |
type: str |
| 24 |
default: unix:///var/run/docker.sock |
| 25 |
aliases: |
| 26 |
- docker_url |
| 27 |
tls_hostname: |
| 28 |
description: |
| 29 |
- When verifying the authenticity of the Docker Host server, provide the expected name of the server. |
| 30 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_HOSTNAME) will be used instead. |
| 31 |
If the environment variable is not set, the default value will be used. |
| 32 |
- Note that this option had a default value V(localhost) in older versions. It was removed in community.docker 3.0.0. |
| 33 |
- B(Note:) this option is no longer supported for Docker SDK for Python 7.0.0+. Specifying it with Docker SDK for Python |
| 34 |
7.0.0 or newer will lead to an error. |
| 35 |
type: str |
| 36 |
api_version: |
| 37 |
description: |
| 38 |
- The version of the Docker API running on the Docker Host. |
| 39 |
- Defaults to the latest version of the API supported by Docker SDK for Python and the docker daemon. |
| 40 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_API_VERSION) will be used instead. |
| 41 |
If the environment variable is not set, the default value will be used. |
| 42 |
type: str |
| 43 |
default: auto |
| 44 |
aliases: |
| 45 |
- docker_api_version |
| 46 |
timeout: |
| 47 |
description: |
| 48 |
- The maximum amount of time in seconds to wait on a response from the API. |
| 49 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TIMEOUT) will be used instead. |
| 50 |
If the environment variable is not set, the default value will be used. |
| 51 |
type: int |
| 52 |
default: 60 |
| 53 |
ca_path: |
| 54 |
description: |
| 55 |
- Use a CA certificate when performing server verification by providing the path to a CA certificate file. |
| 56 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(ca.pem) |
| 57 |
from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 58 |
- This option was called O(ca_cert) and got renamed to O(ca_path) in community.docker 3.6.0. The old name has been added |
| 59 |
as an alias and can still be used. |
| 60 |
type: path |
| 61 |
aliases: |
| 62 |
- ca_cert |
| 63 |
- tls_ca_cert |
| 64 |
- cacert_path |
| 65 |
client_cert: |
| 66 |
description: |
| 67 |
- Path to the client's TLS certificate file. |
| 68 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(cert.pem) |
| 69 |
from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 70 |
type: path |
| 71 |
aliases: |
| 72 |
- tls_client_cert |
| 73 |
- cert_path |
| 74 |
client_key: |
| 75 |
description: |
| 76 |
- Path to the client's TLS key file. |
| 77 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(key.pem) |
| 78 |
from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 79 |
type: path |
| 80 |
aliases: |
| 81 |
- tls_client_key |
| 82 |
- key_path |
| 83 |
tls: |
| 84 |
description: |
| 85 |
- Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that |
| 86 |
if O(validate_certs) is set to V(true) as well, it will take precedence. |
| 87 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS) will be used instead. If |
| 88 |
the environment variable is not set, the default value will be used. |
| 89 |
type: bool |
| 90 |
default: false |
| 91 |
use_ssh_client: |
| 92 |
description: |
| 93 |
- For SSH transports, use the C(ssh) CLI tool instead of paramiko. |
| 94 |
- Requires Docker SDK for Python 4.4.0 or newer. |
| 95 |
type: bool |
| 96 |
default: false |
| 97 |
version_added: 1.5.0 |
| 98 |
validate_certs: |
| 99 |
description: |
| 100 |
- Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. |
| 101 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_VERIFY) will be used instead. |
| 102 |
If the environment variable is not set, the default value will be used. |
| 103 |
type: bool |
| 104 |
default: false |
| 105 |
aliases: |
| 106 |
- tls_verify |
| 107 |
debug: |
| 108 |
description: |
| 109 |
- Debug mode. |
| 110 |
type: bool |
| 111 |
default: false |
| 112 |
|
| 113 |
notes: |
| 114 |
- Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define |
| 115 |
E(DOCKER_HOST), E(DOCKER_TLS_HOSTNAME), E(DOCKER_API_VERSION), E(DOCKER_CERT_PATH), E(DOCKER_TLS), E(DOCKER_TLS_VERIFY) |
| 116 |
and E(DOCKER_TIMEOUT). If you are using docker machine, run the script shipped with the product that sets up the environment. |
| 117 |
It will set these variables for you. See U(https://docs.docker.com/machine/reference/env/) for more details. |
| 118 |
- When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for |
| 119 |
Python, version 2.4 or newer, this can be done by installing C(docker[tls]) with M(ansible.builtin.pip). |
| 120 |
- Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. |
| 121 |
In general, it will use C($HOME/.docker/config.json) if the E(DOCKER_CONFIG) environment variable is not specified, and |
| 122 |
use C($DOCKER_CONFIG/config.json) otherwise. |
| 123 |
""" |
| 124 |
|
| 125 |
# For plugins: allow to define common options with Ansible variables |
| 126 |
|
| 127 |
VAR_NAMES = r""" |
| 128 |
options: |
| 129 |
docker_host: |
| 130 |
vars: |
| 131 |
- name: ansible_docker_docker_host |
| 132 |
tls_hostname: |
| 133 |
vars: |
| 134 |
- name: ansible_docker_tls_hostname |
| 135 |
api_version: |
| 136 |
vars: |
| 137 |
- name: ansible_docker_api_version |
| 138 |
timeout: |
| 139 |
vars: |
| 140 |
- name: ansible_docker_timeout |
| 141 |
ca_path: |
| 142 |
vars: |
| 143 |
- name: ansible_docker_ca_cert |
| 144 |
- name: ansible_docker_ca_path |
| 145 |
version_added: 3.6.0 |
| 146 |
client_cert: |
| 147 |
vars: |
| 148 |
- name: ansible_docker_client_cert |
| 149 |
client_key: |
| 150 |
vars: |
| 151 |
- name: ansible_docker_client_key |
| 152 |
tls: |
| 153 |
vars: |
| 154 |
- name: ansible_docker_tls |
| 155 |
validate_certs: |
| 156 |
vars: |
| 157 |
- name: ansible_docker_validate_certs |
| 158 |
""" |
| 159 |
|
| 160 |
# Additional, more specific stuff for minimal Docker SDK for Python version >= 2.0. |
| 161 |
|
| 162 |
DOCKER_PY_2_DOCUMENTATION = r""" |
| 163 |
options: {} |
| 164 |
notes: |
| 165 |
- This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to |
| 166 |
communicate with the Docker daemon. |
| 167 |
requirements: |
| 168 |
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/) |
| 169 |
Python module has been superseded by L(docker,https://pypi.org/project/docker/) |
| 170 |
(see L(here,https://github.com/docker/docker-py/issues/1310) for details). |
| 171 |
This module does B(not) work with docker-py." |
| 172 |
""" |
| 173 |
|
| 174 |
# Docker doc fragment when using the vendored API access code |
| 175 |
API_DOCUMENTATION = r""" |
| 176 |
options: |
| 177 |
docker_host: |
| 178 |
description: |
| 179 |
- The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the |
| 180 |
TCP connection string. For example, V(tcp://192.0.2.23:2376). If TLS is used to encrypt the connection, |
| 181 |
the module will automatically replace C(tcp) in the connection URL with C(https). |
| 182 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_HOST) will be used |
| 183 |
instead. If the environment variable is not set, the default value will be used. |
| 184 |
type: str |
| 185 |
default: unix:///var/run/docker.sock |
| 186 |
aliases: |
| 187 |
- docker_url |
| 188 |
tls_hostname: |
| 189 |
description: |
| 190 |
- When verifying the authenticity of the Docker Host server, provide the expected name of the server. |
| 191 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_HOSTNAME) will |
| 192 |
be used instead. If the environment variable is not set, the default value will be used. |
| 193 |
- Note that this option had a default value V(localhost) in older versions. It was removed in community.docker 3.0.0. |
| 194 |
type: str |
| 195 |
api_version: |
| 196 |
description: |
| 197 |
- The version of the Docker API running on the Docker Host. |
| 198 |
- Defaults to the latest version of the API supported by this collection and the docker daemon. |
| 199 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_API_VERSION) will be |
| 200 |
used instead. If the environment variable is not set, the default value will be used. |
| 201 |
type: str |
| 202 |
default: auto |
| 203 |
aliases: |
| 204 |
- docker_api_version |
| 205 |
timeout: |
| 206 |
description: |
| 207 |
- The maximum amount of time in seconds to wait on a response from the API. |
| 208 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TIMEOUT) will be used |
| 209 |
instead. If the environment variable is not set, the default value will be used. |
| 210 |
type: int |
| 211 |
default: 60 |
| 212 |
ca_path: |
| 213 |
description: |
| 214 |
- Use a CA certificate when performing server verification by providing the path to a CA certificate file. |
| 215 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 216 |
the file C(ca.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 217 |
- This option was called O(ca_cert) and got renamed to O(ca_path) in community.docker 3.6.0. The old name has |
| 218 |
been added as an alias and can still be used. |
| 219 |
type: path |
| 220 |
aliases: |
| 221 |
- ca_cert |
| 222 |
- tls_ca_cert |
| 223 |
- cacert_path |
| 224 |
client_cert: |
| 225 |
description: |
| 226 |
- Path to the client's TLS certificate file. |
| 227 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 228 |
the file C(cert.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 229 |
type: path |
| 230 |
aliases: |
| 231 |
- tls_client_cert |
| 232 |
- cert_path |
| 233 |
client_key: |
| 234 |
description: |
| 235 |
- Path to the client's TLS key file. |
| 236 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 237 |
the file C(key.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 238 |
type: path |
| 239 |
aliases: |
| 240 |
- tls_client_key |
| 241 |
- key_path |
| 242 |
tls: |
| 243 |
description: |
| 244 |
- Secure the connection to the API by using TLS without verifying the authenticity of the Docker host |
| 245 |
server. Note that if O(validate_certs) is set to V(true) as well, it will take precedence. |
| 246 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS) will be used |
| 247 |
instead. If the environment variable is not set, the default value will be used. |
| 248 |
type: bool |
| 249 |
default: false |
| 250 |
use_ssh_client: |
| 251 |
description: |
| 252 |
- For SSH transports, use the C(ssh) CLI tool instead of paramiko. |
| 253 |
type: bool |
| 254 |
default: false |
| 255 |
version_added: 1.5.0 |
| 256 |
validate_certs: |
| 257 |
description: |
| 258 |
- Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. |
| 259 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_VERIFY) will be |
| 260 |
used instead. If the environment variable is not set, the default value will be used. |
| 261 |
type: bool |
| 262 |
default: false |
| 263 |
aliases: |
| 264 |
- tls_verify |
| 265 |
debug: |
| 266 |
description: |
| 267 |
- Debug mode |
| 268 |
type: bool |
| 269 |
default: false |
| 270 |
|
| 271 |
notes: |
| 272 |
- Connect to the Docker daemon by providing parameters with each task or by defining environment variables. |
| 273 |
You can define E(DOCKER_HOST), E(DOCKER_TLS_HOSTNAME), E(DOCKER_API_VERSION), E(DOCKER_CERT_PATH), |
| 274 |
E(DOCKER_TLS), E(DOCKER_TLS_VERIFY) and E(DOCKER_TIMEOUT). If you are using docker machine, run the script shipped |
| 275 |
with the product that sets up the environment. It will set these variables for you. See |
| 276 |
U(https://docs.docker.com/machine/reference/env/) for more details. |
| 277 |
# - Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. |
| 278 |
# In general, it will use C($HOME/.docker/config.json) if the E(DOCKER_CONFIG) environment variable is not specified, |
| 279 |
# and use C($DOCKER_CONFIG/config.json) otherwise. |
| 280 |
- This module does B(not) use the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to |
| 281 |
communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this |
| 282 |
collection. |
| 283 |
requirements: |
| 284 |
- requests |
| 285 |
- pywin32 (when using named pipes on Windows 32) |
| 286 |
- paramiko (when using SSH with O(use_ssh_client=false)) |
| 287 |
- pyOpenSSL (when using TLS) |
| 288 |
""" |
| 289 |
|
| 290 |
# Docker doc fragment when using the Docker CLI |
| 291 |
CLI_DOCUMENTATION = r""" |
| 292 |
options: |
| 293 |
docker_cli: |
| 294 |
description: |
| 295 |
- Path to the Docker CLI. If not provided, will search for Docker CLI on the E(PATH). |
| 296 |
type: path |
| 297 |
docker_host: |
| 298 |
description: |
| 299 |
- The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the |
| 300 |
TCP connection string. For example, V(tcp://192.0.2.23:2376). If TLS is used to encrypt the connection, |
| 301 |
the module will automatically replace C(tcp) in the connection URL with C(https). |
| 302 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_HOST) will be used |
| 303 |
instead. If the environment variable is not set, the default value will be used. |
| 304 |
- Mutually exclusive with O(cli_context). If neither O(docker_host) nor O(cli_context) are provided, the |
| 305 |
value V(unix:///var/run/docker.sock) is used. |
| 306 |
type: str |
| 307 |
aliases: |
| 308 |
- docker_url |
| 309 |
tls_hostname: |
| 310 |
description: |
| 311 |
- When verifying the authenticity of the Docker Host server, provide the expected name of the server. |
| 312 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_HOSTNAME) will |
| 313 |
be used instead. If the environment variable is not set, the default value will be used. |
| 314 |
type: str |
| 315 |
api_version: |
| 316 |
description: |
| 317 |
- The version of the Docker API running on the Docker Host. |
| 318 |
- Defaults to the latest version of the API supported by this collection and the docker daemon. |
| 319 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_API_VERSION) will be |
| 320 |
used instead. If the environment variable is not set, the default value will be used. |
| 321 |
type: str |
| 322 |
default: auto |
| 323 |
aliases: |
| 324 |
- docker_api_version |
| 325 |
ca_path: |
| 326 |
description: |
| 327 |
- Use a CA certificate when performing server verification by providing the path to a CA certificate file. |
| 328 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 329 |
the file C(ca.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 330 |
type: path |
| 331 |
aliases: |
| 332 |
- ca_cert |
| 333 |
- tls_ca_cert |
| 334 |
- cacert_path |
| 335 |
client_cert: |
| 336 |
description: |
| 337 |
- Path to the client's TLS certificate file. |
| 338 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 339 |
the file C(cert.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 340 |
type: path |
| 341 |
aliases: |
| 342 |
- tls_client_cert |
| 343 |
- cert_path |
| 344 |
client_key: |
| 345 |
description: |
| 346 |
- Path to the client's TLS key file. |
| 347 |
- If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, |
| 348 |
the file C(key.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. |
| 349 |
type: path |
| 350 |
aliases: |
| 351 |
- tls_client_key |
| 352 |
- key_path |
| 353 |
tls: |
| 354 |
description: |
| 355 |
- Secure the connection to the API by using TLS without verifying the authenticity of the Docker host |
| 356 |
server. Note that if O(validate_certs) is set to V(true) as well, it will take precedence. |
| 357 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS) will be used |
| 358 |
instead. If the environment variable is not set, the default value will be used. |
| 359 |
type: bool |
| 360 |
default: false |
| 361 |
validate_certs: |
| 362 |
description: |
| 363 |
- Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. |
| 364 |
- If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_VERIFY) will be |
| 365 |
used instead. If the environment variable is not set, the default value will be used. |
| 366 |
type: bool |
| 367 |
default: false |
| 368 |
aliases: |
| 369 |
- tls_verify |
| 370 |
# debug: |
| 371 |
# description: |
| 372 |
# - Debug mode |
| 373 |
# type: bool |
| 374 |
# default: false |
| 375 |
cli_context: |
| 376 |
description: |
| 377 |
- The Docker CLI context to use. |
| 378 |
- Mutually exclusive with O(docker_host). |
| 379 |
type: str |
| 380 |
|
| 381 |
notes: |
| 382 |
- Connect to the Docker daemon by providing parameters with each task or by defining environment variables. |
| 383 |
You can define E(DOCKER_HOST), E(DOCKER_TLS_HOSTNAME), E(DOCKER_API_VERSION), E(DOCKER_CERT_PATH), |
| 384 |
E(DOCKER_TLS), E(DOCKER_TLS_VERIFY) and E(DOCKER_TIMEOUT). If you are using docker machine, run the script shipped |
| 385 |
with the product that sets up the environment. It will set these variables for you. See |
| 386 |
U(https://docs.docker.com/machine/reference/env/) for more details. |
| 387 |
- This module does B(not) use the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to |
| 388 |
communicate with the Docker daemon. It directly calls the Docker CLI program. |
| 389 |
""" |