community.docker.docker_context_info module – Retrieve information on Docker contexts for the current user

Note

This module is part of the community.docker collection (version 4.6.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.docker.

To use it in a playbook, specify: community.docker.docker_context_info.

New in community.docker 4.4.0

Synopsis

  • Return information on Docker contexts.

  • This includes some generic information, as well as a contexts[].config dictionary that can be used for module defaults for all community.docker modules that use the community.docker.docker module defaults group.

Parameters

Parameter

Comments

cli_context

string

Override for the default context’s name.

This is preferably used for context selection when only_current=true, and it is used to compute the return values contexts[].current and current_context_name.

name

string

A specific Docker CLI context to query.

The module will fail if this context does not exist. If you simply want to query whether a context exists, do not specify this parameter and use Jinja2 to search the resulting list for a context of the given name instead.

Mutually exclusive with only_current.

only_current

boolean

If set to true, contexts will just contain the current context and none else.

If set to false (default), contexts will list all contexts, unless name is specified.

Mutually exclusive to name.

Choices:

  • false ← (default)

  • true

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

idempotent

Support: full

This action does not modify state.

When run twice in a row outside check mode, with the same arguments, the second invocation indicates no change.

This assumes that the system controlled/queried by the module has not changed in a relevant way.

Examples

- name: Get infos on contexts
  community.docker.docker_context_info:
  register: result

- name: Show all contexts
  ansible.builtin.debug:
    msg: "{{ result.contexts }}"

- name: Get current context
  community.docker.docker_context_info:
    only_current: true
  register: docker_current_context

- name: Run community.docker modules with current context
  module_defaults:
    group/community.docker.docker: "{{ docker_current_context.contexts[0].config }}"
  block:
    - name: Task using the current context
      community.docker.docker_container:
        image: ubuntu:latest
        name: ubuntu
        state: started

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

contexts

list / elements=dictionary

A list of all contexts (only_current=false, name not specified), only the current context (only_current=true), or the requested context (name specified).

Returned: success

config

dictionary

In case the context is for Docker, contains option values to configure the community.docker modules to use this context.

Note that the exact values returned here and their values might change over time if incompatibilities to existing modules are found. The goal is that this configuration works fine with all modules in this collection, but we do not have the capabilities to test all possible configuration options at the moment.

Returned: success

Sample: {}

ca_path

boolean

The CA certificate used to validate the Docker daemon’s certificate.

Returned: success, context is for Docker, TLS config is present, and CA cert is present

Sample: "/path/to/ca-cert.pem"

client_cert

boolean

The client certificate to authenticate with to the Docker daemon.

Returned: success, context is for Docker, TLS config is present, and client cert info is present

Sample: "/path/to/client-cert.pem"

client_key

boolean

The client certificate’s key to authenticate with to the Docker daemon.

Returned: success, context is for Docker, TLS config is present, and client cert info is present

Sample: "/path/to/client-key.pem"

docker_host

string

The Docker daemon to connect to.

Returned: success and context is for Docker

Sample: "unix:///var/run/docker.sock"

tls

boolean

Whether the Docker context should use an unvalidated TLS connection.

Returned: success and context is for Docker

Sample: false

validate_certs

boolean

Whether the Docker context should use a validated TLS connection.

Returned: success, context is for Docker, and TLS config is present

Sample: true

current

boolean

Whether this context is the current one.

Returned: success

Sample: true

description

boolean

The context’s description, if available.

Returned: success

Sample: "My context"

meta_path

string

The path to the context’s meta directory.

Not present for contexts[].name=default.

Returned: success

Sample: "/home/felix/.docker/contexts/meta/0123456789abcdef01234567890abcdef0123456789abcdef0123456789abcde"

name

boolean

The context’s name.

Returned: success

Sample: "default"

tls_path

string

The path to the context’s TLS config directory.

Not present for contexts[].name=default.

Returned: success

Sample: "/home/user/.docker/contexts/tls/0123456789abcdef01234567890abcdef0123456789abcdef0123456789abcde/"

current_context_name

string

The name of the current Docker context.

Returned: success

Sample: "default"

Authors

  • Felix Fontein (@felixfontein)