community.general.docker_node (1.3.14) — module

Manage Docker Swarm node

Authors: Piotr Wojciechowski (@WojciechowskiPiotr), Thierry Bouvet (@tbouvet)

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

Manages the Docker nodes via Swarm Manager.

This module allows to change the node's role, its availability, and to modify, add or remove node labels.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set node role
  community.general.docker_node:
    hostname: mynode
    role: manager
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set node availability
  community.general.docker_node:
    hostname: mynode
    availability: drain
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Replace node labels with new labels
  community.general.docker_node:
    hostname: mynode
    labels:
      key: value
    labels_state: replace
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Merge node labels and new labels
  community.general.docker_node:
    hostname: mynode
    labels:
      key: value
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove all labels assigned to node
  community.general.docker_node:
    hostname: mynode
    labels_state: replace
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove selected labels from the node
  community.general.docker_node:
    hostname: mynode
    labels_to_remove:
      - key1
      - key2

Inputs

    
tls:
    default: false
    description:
    - Secure the connection to the API by using TLS without verifying the authenticity
      of the Docker host server. Note that if I(validate_certs) is set to C(yes) as well,
      it will take precedence.
    - If the value is not specified in the task, the value of environment variable C(DOCKER_TLS)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: bool

role:
    choices:
    - manager
    - worker
    description: Node role to assign. If not provided then node role remains unchanged.
    type: str

debug:
    default: false
    description:
    - Debug mode
    type: bool

labels:
    description:
    - 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 I(hostname).
      Use M(community.general.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 I(labels_state) and I(labels_to_remove) parameters values. See description below.
    type: dict

ca_cert:
    aliases:
    - tls_ca_cert
    - cacert_path
    description:
    - 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 C(DOCKER_CERT_PATH)
      is set, the file C(ca.pem) from the directory specified in the environment variable
      C(DOCKER_CERT_PATH) will be used.
    type: path

timeout:
    default: 60
    description:
    - 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 C(DOCKER_TIMEOUT)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: int

hostname:
    description:
    - 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.
    required: true
    type: str

client_key:
    aliases:
    - tls_client_key
    - key_path
    description:
    - Path to the client's TLS key file.
    - If the value is not specified in the task and the environment variable C(DOCKER_CERT_PATH)
      is set, the file C(key.pem) from the directory specified in the environment variable
      C(DOCKER_CERT_PATH) will be used.
    type: path

api_version:
    aliases:
    - docker_api_version
    default: auto
    description:
    - 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 C(DOCKER_API_VERSION)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

client_cert:
    aliases:
    - tls_client_cert
    - cert_path
    description:
    - Path to the client's TLS certificate file.
    - If the value is not specified in the task and the environment variable C(DOCKER_CERT_PATH)
      is set, the file C(cert.pem) from the directory specified in the environment variable
      C(DOCKER_CERT_PATH) will be used.
    type: path

docker_host:
    aliases:
    - docker_url
    default: unix://var/run/docker.sock
    description:
    - 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, C(tcp://192.0.2.23:2376).
      If TLS is used to encrypt the connection, the module will automatically replace
      C(tcp) in the connection URL with C(https).
    - If the value is not specified in the task, the value of environment variable C(DOCKER_HOST)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

ssl_version:
    description:
    - 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 C(DOCKER_SSL_VERSION)
      will be used instead.
    type: str

availability:
    choices:
    - active
    - pause
    - drain
    description: Node availability to assign. If not provided then node availability remains
      unchanged.
    type: str

labels_state:
    choices:
    - merge
    - replace
    default: merge
    description:
    - It defines the operation on the labels assigned to node and labels specified in
      I(labels) option.
    - Set to C(merge) to combine labels provided in I(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 I(labels) will remain unchanged. If I(labels) is empty then no changes
      will be made.
    - Set to C(replace) to replace all assigned labels with provided ones. If I(labels)
      is empty then all labels assigned to the node will be removed.
    type: str

tls_hostname:
    default: localhost
    description:
    - 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 C(DOCKER_TLS_HOSTNAME)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

validate_certs:
    aliases:
    - tls_verify
    default: false
    description:
    - 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 C(DOCKER_TLS_VERIFY)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: bool

labels_to_remove:
    description:
    - 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 I(labels_to_remove) and I(labels), then value provided
      in I(labels) remains assigned to the node.
    - If I(labels_state) is C(replace) and I(labels) is not provided or empty then all
      labels assigned to node are removed and I(labels_to_remove) is ignored.
    elements: str
    type: list

Outputs

node:
  description: Information about node after 'update' operation
  returned: success
  type: dict