community.general.docker_stack (1.3.14) — module

docker stack module

Authors: Dario Zanzico (@dariko)

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

Manage docker stacks using the 'docker stack' command on the target node (see examples).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Deploy stack from a compose file
    community.general.docker_stack:
      state: present
      name: mystack
      compose:
        - /opt/docker-compose.yml
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Deploy stack from base compose file and override the web service
    community.general.docker_stack:
      state: present
      name: mystack
      compose:
        - /opt/docker-compose.yml
        - version: '3'
          services:
            web:
              image: nginx:latest
              environment:
                ENVVAR: envvar
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove stack
    community.general.docker_stack:
      name: mystack
      state: absent

Inputs

    
name:
    description:
    - Stack name
    required: true
    type: str

prune:
    default: false
    description:
    - If true will add the C(--prune) option to the C(docker stack deploy) command. This
      will have docker remove the services not present in the current stack definition.
    type: bool

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Service state.
    type: str

compose:
    default: []
    description:
    - List of compose definitions. Any element may be a string referring to the path of
      the compose file on the target host or the YAML contents of a compose file nested
      as dictionary.
    elements: raw
    type: list

resolve_image:
    choices:
    - always
    - changed
    - never
    description:
    - If set will add the C(--resolve-image) option to the C(docker stack deploy) command.
      This will have docker query the registry to resolve image digest and supported platforms.
      If not set, docker use "always" by default.
    type: str

absent_retries:
    default: 0
    description:
    - If C(>0) and I(state) is C(absent) the module will retry up to I(absent_retries)
      times to delete the stack until all the resources have been effectively deleted.
      If the last try still reports the stack as not completely removed the module will
      fail.
    type: int

with_registry_auth:
    default: false
    description:
    - If true will add the C(--with-registry-auth) option to the C(docker stack deploy)
      command. This will have docker send registry authentication details to Swarm agents.
    type: bool

absent_retries_interval:
    default: 1
    description:
    - Interval in seconds between consecutive I(absent_retries).
    type: int

Outputs

stack_spec_diff:
  description: 'dictionary containing the differences between the ''Spec'' field

    of the stack services before and after applying the new stack

    definition.

    '
  returned: on change
  sample: '"stack_spec_diff": {''test_stack_test_service'': {u''TaskTemplate'': {u''ContainerSpec'':
    {delete: [u''Env'']}}}}

    '
  type: dict