docker_swarm - Manage Swarm cluster¶
New in version 2.7.
Synopsis¶
- Create a new Swarm cluster.
- Add/Remove nodes or managers to an existing cluster.
Requirements¶
The below requirements are needed on the host that executes this module.
Parameters¶
Parameter | Choices/Defaults | Comments |
---|---|---|
advertise_addr |
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. |
|
api_version |
Default: auto
|
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported by docker-py.
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.aliases: docker_api_version |
autolock_managers
bool |
|
If set, generate a key and use it to lock data stored on the managers.
Docker default value is
no . |
ca_force_rotate |
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 . |
|
cacert_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.aliases: tls_ca_cert |
|
cert_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.aliases: tls_client_cert |
|
debug
bool |
|
Debug mode
|
dispatcher_heartbeat_period |
The delay for an agent to send a heartbeat to the dispatcher.
Docker default value is
5s . |
|
docker_host |
Default: unix://var/run/docker.sock
|
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.aliases: docker_url |
election_tick |
Amount of ticks (in seconds) needed without a leader to trigger a new election.
Docker default value is
10s . |
|
force
bool |
|
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. |
heartbeat_tick |
Amount of ticks (in seconds) between each heartbeat.
Docker default value is
1s . |
|
join_token |
Swarm token used to join a swarm cluster.
Used with state=join.
|
|
keep_old_snapshots |
Number of snapshots to keep beyond the current snapshot.
Docker default value is
0 . |
|
key_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.aliases: tls_client_key |
|
labels |
User-defined key/value metadata.
|
|
listen_addr |
Default: 0.0.0.0:2377
|
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.
|
log_entries_for_slow_followers |
Number of log entries to keep around to sync up slow followers after a snapshot is created.
|
|
name |
The name of the swarm.
|
|
node_cert_expiry |
Automatic expiry for nodes certificates.
Docker default value is
3months . |
|
node_id |
Swarm id of the node to remove.
Used with state=remove.
|
|
remote_addrs |
Remote address of a manager to connect to.
Used with state=join.
|
|
rotate_manager_token
bool |
|
Rotate the manager join token.
|
rotate_worker_token
bool |
|
Rotate the worker join token.
|
signing_ca_cert |
The desired signing CA certificate for all swarm node TLS leaf certificates, in PEM format.
|
|
signing_ca_key |
The desired signing CA key for all swarm node TLS leaf certificates, in PEM format.
|
|
snapshot_interval |
Number of logs entries between snapshot.
Docker default value is
10000 . |
|
ssl_version |
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
required |
|
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.Set to
inspect to display swarm informations. |
task_history_retention_limit |
Maximum number of tasks history stored.
Docker default value is
5 . |
|
timeout |
Default: 60
|
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. |
tls
bool |
|
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server.
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. |
tls_hostname |
Default: localhost
|
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. |
tls_verify
bool |
|
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. |
Notes¶
Note
- 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://docker-py.readthedocs.io/en/stable/machine/ 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 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 theDOCKER_CONFIG
environment variable is not specified, and use$DOCKER_CONFIG/config.json
otherwise.
Examples¶
- name: Init a new swarm with default parameters
docker_swarm:
state: present
- name: Update swarm configuration
docker_swarm:
state: present
election_tick: 5
- name: Add nodes
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
docker_swarm:
state: absent
- name: Remove a swarm manager
docker_swarm:
state: absent
force: true
- name: Remove node from swarm
docker_swarm:
state: remove
node_id: mynode
- name: Inspect swarm
docker_swarm:
state: inspect
register: swarm_info
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description | ||
---|---|---|---|---|
actions
list
|
when action failed. |
Provides the actions done on the swarm.
|
||
swarm_facts
complex
|
success |
Informations about swarm.
|
||
JoinTokens
complex
|
success |
Tokens to connect to the Swarm.
|
||
Manager
str
|
success |
Token to create a new manager node
|
||
Worker
str
|
success |
Token to create a new worker node
|
Status¶
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
Maintenance¶
This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.
For a list of other modules that are also maintained by the Ansible Community, see here.
Author¶
- Thierry Bouvet (@tbouvet)
Hint
If you notice any issues in this documentation you can edit this document to improve it.