arillso.container.docker_compose_v2 role – Configure and manage Docker Compose environment using Ansible

Note

This role is part of the arillso.container collection (version 0.0.7).

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 arillso.container.

To use it in a playbook, specify: arillso.container.docker_compose_v2.

Entry point main – Configure and manage Docker Compose environment using Ansible

Synopsis

  • This spec outlines parameters for configuring Docker Compose with Ansible.

  • It includes Docker Compose version, package names, directory paths, configuration methods, and project name.

Parameters

Parameter

Comments

docker_compose_v2_api_version

string

Docker API version to use. Set to ‘auto’ for automatic selection of the latest supported version.

‘auto’ automatically selects the latest supported API version.

Default: "auto"

docker_compose_v2_ca_cert

string

Path to the CA certificate for server verification.

docker_compose_v2_cli_context

string

Specify the Docker CLI context to use with Docker Compose v2.

docker_compose_v2_client_cert

string

Path to the client’s TLS certificate for Docker daemon communication.

docker_compose_v2_client_key

string

Path to the client’s TLS key for Docker daemon communication.

docker_compose_v2_config

any

Inline configuration for Docker Compose, defined as an array of multi-line YAML strings.

Default: []

docker_compose_v2_debug

boolean

Enable or disable debug mode.

Choices:

  • false ← (default)

  • true

docker_compose_v2_dependencies

boolean

Include or exclude linked services.

Choices:

  • false

  • true ← (default)

docker_compose_v2_directory

string

Full path to the Docker Compose project directory, constructed from docker_compose_v2_directory_path and docker_compose_v2_project.

Default: "{{ docker_compose_v2_directory_path }}/{{ docker_compose_v2_project }}"

docker_compose_v2_directory_path

string

Base directory path for storing Docker Compose configuration files.

Ensure the specified path exists and is writable.

Default: "/etc/docker/compose"

docker_compose_v2_docker_cli

string

Path to the Docker CLI executable, if not in standard PATH.

docker_compose_v2_docker_host

string

Docker host URL or Unix socket path for API connection. Defaults to the standard Unix socket.

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

docker_compose_v2_env_file

string

Custom path to an environment file, relative to the project source directory.

docker_compose_v2_files

list / elements=string

List of Compose file names, relative to project_src, to override default docker-compose.yml.

docker_compose_v2_hostname_check

boolean

Check Docker daemon’s hostname against the name provided in the client certificate. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_nocache

boolean

Control the use of cache during the image build. Set to ‘true’ to ignore cache.

Choices:

  • false ← (default)

  • true

docker_compose_v2_packages

list / elements=string

List of Docker Compose packages for installation. Appends the specified version to the package name if docker_compose_v2_version is set.

Useful for ensuring consistency across environments by locking to a specific version.

Default: ["{'name': \"{{ 'docker-compose-plugin=' + docker_compose_v2_version if docker_compose_v2_version != '' else 'docker-compose-plugin' }}\"}"]

docker_compose_v2_profiles

list / elements=string

List of profiles to enable when starting services, applicable for docker-compose v1.28.0 or later.

docker_compose_v2_project

string

Name of the Docker Compose project, utilized to construct the full Docker Compose directory path.

Default: ""

docker_compose_v2_project_name

string

Custom name for the Docker Compose project. If not set, the default name is derived from the project directory.

docker_compose_v2_pull

string

Always pull images before starting the application. Set to ‘true’ to enable.

docker_compose_v2_recreate

string

Strategy for container recreation: ‘always’, ‘never’, or ‘smart’ (default).

Default: "smart"

docker_compose_v2_remove_images

string

Option to remove images when state is ‘absent’. Choices are ‘all’ or ‘local’.

docker_compose_v2_remove_orphans

boolean

Remove containers for services not defined in the current Compose file. Default is ‘false’.

Useful for cleaning up containers that are no longer needed.

Choices:

  • false ← (default)

  • true

docker_compose_v2_remove_volumes

boolean

Remove data volumes when state is ‘absent’. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_restarted

boolean

Restart all containers when state is ‘present’. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_scale

dictionary

Dictionary defining service scaling: service name as key, number of containers as value.

docker_compose_v2_services

list / elements=string

List of specific services to operate on. If empty, applies to all services in the Compose file.

docker_compose_v2_ssl_version

string

Specify a valid SSL version number for secure communication. Uses the default value determined by the SSL Python module if not set.

docker_compose_v2_state

string

Desired state of the Docker Compose project: ‘present’ (default) or ‘absent’.

‘present’ ensures the project is running, ‘absent’ removes it.

Default: "present"

docker_compose_v2_stopped

boolean

Stop all containers when state is ‘present’. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_timeout

integer

Timeout in seconds for container shutdown operations. Set a specific value to override the default timeout.

docker_compose_v2_tls

boolean

Use TLS for API connection without verifying the Docker host server’s authenticity. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_tls_hostname

string

Expected hostname of the Docker Host server for TLS verification.

docker_compose_v2_use_file

boolean

Boolean flag to choose Docker Compose execution method: ‘true’ for file-based, ‘false’ for inline configuration.

‘true’ uses a file for configuration, while ‘false’ utilizes an inline configuration.

Choices:

  • false

  • true ← (default)

docker_compose_v2_validate_certs

boolean

Verify the Docker host server’s authenticity when using TLS. Default is ‘false’.

Choices:

  • false ← (default)

  • true

docker_compose_v2_version

string

Specifies the version of Docker Compose to install. Leave blank for the latest version.

Specify a specific version to install an older or specific release.

Default: ""