community / community.general / 0.1.4 / module / docker_swarm_info Retrieves facts about Docker Swarm cluster. Authors: Piotr Wojciechowski (@WojciechowskiPiotr)community.general.docker_swarm_info (0.1.4) — module
Install with ansible-galaxy collection install community.general:==0.1.4
collections: - name: community.general version: 0.1.4
Retrieves facts about a Docker Swarm.
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.
- name: Get info on Docker Swarm docker_swarm_info: ignore_errors: yes register: result
- name: Inform about basic flags 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 docker_swarm_info: nodes: yes register: result
- name: Get info on Docker Swarm and extended list of registered nodes docker_swarm_info: nodes: yes verbose_output: yes register: result
- name: Get info on Docker Swarm and filtered list of registered nodes docker_swarm_info: nodes: yes nodes_filter: name: mynode register: result
- debug: var: result.swarm_facts
- name: Get the swarm unlock key docker_swarm_info: unlock_key: yes register: result
- debug: var: result.swarm_unlock_key
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 debug: default: false description: - Debug mode type: bool nodes: default: false description: - Whether to list swarm nodes. type: bool tasks: default: false description: - Whether to list containers. type: bool 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 services: default: false description: - Whether to list swarm services. type: bool 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 unlock_key: default: false description: - Whether to retrieve the swarm unlock key. type: bool 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 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 nodes_filters: description: - A dictionary of filter values used for selecting nodes to list. - 'For example, C(name: mynode).' - See L(the docker documentation,https://docs.docker.com/engine/reference/commandline/node_ls/#filtering) for more information on possible filters. type: dict tasks_filters: description: - A dictionary of filter values used for selecting tasks to list. - 'For example, C(node: mynode-1).' - See L(the docker documentation,https://docs.docker.com/engine/reference/commandline/service_ps/#filtering) for more information on possible filters. type: dict 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 verbose_output: default: false description: - When set to C(yes) and I(nodes), I(services) or I(tasks) is set to C(yes), then the module 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 U(https://docs.docker.com/engine/api/). - The verbose output in this module contains only subset of information returned by I(_info) module for each type of the objects. type: bool services_filters: description: - A dictionary of filter values used for selecting services to list. - 'For example, C(name: myservice).' - See L(the docker documentation,https://docs.docker.com/engine/reference/commandline/service_ls/#filtering) for more information on possible filters. type: dict
can_talk_to_docker: description: - Will be C(true) if the module can talk to the docker daemon. returned: both on success and on error type: bool docker_swarm_active: description: - Will be C(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 type: bool docker_swarm_manager: description: - Will be C(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 C(true), the module will not fail. returned: both on success and on error type: bool nodes: description: - List of dict objects containing the basic information about each volume. Keys matches the C(docker node ls) output unless I(verbose_output=yes). See description for I(verbose_output). elements: dict returned: When I(nodes) is C(yes) type: list services: description: - List of dict objects containing the basic information about each volume. Keys matches the C(docker service ls) output unless I(verbose_output=yes). See description for I(verbose_output). elements: dict returned: When I(services) is C(yes) type: list swarm_facts: description: - Facts representing the basic state of the docker Swarm cluster. - Contains tokens to connect to the Swarm returned: always type: dict swarm_unlock_key: description: - Contains the key needed to unlock the swarm. returned: When I(unlock_key) is C(true). type: str tasks: description: - List of dict objects containing the basic information about each volume. Keys matches the C(docker service ps) output unless I(verbose_output=yes). See description for I(verbose_output). elements: dict returned: When I(tasks) is C(yes) type: list