New in version 2.1.
The below requirements are needed on the host that executes this module.
Parameter |
Choices/Defaults |
Comments |
---|---|---|
api_version
|
Default:
default provided by docker-py
|
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported by docker-py.
aliases: docker_api_version |
build
|
|
Use with state present to always build images prior to starting the application.
Same as running docker-compose build with the pull option.
Images will only be rebuilt if Docker detects a change in the Dockerfile or build directory contents.
Use the
nocache option to ignore the image cache when performing the build.If an existing image is replaced, services using the image will be recreated unless
recreate is never. |
cacert_path
|
|
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
aliases: tls_ca_cert |
cert_path
|
|
Path to the client's TLS certificate file.
aliases: tls_client_cert |
debug
|
|
Include actions in the return values.
|
definition
|
|
Provide docker-compose yaml describing one or more services, networks and volumes.
Mutually exclusive with
project_src and files . |
dependencies
|
|
When
state is present specify whether or not to include linked services. |
docker_host
|
Default:
unix://var/run/docker.sock
|
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, 'tcp://192.0.2.23:2376'. If TLS is used to encrypt the connection, the module will automatically replace 'tcp' in the connection URL with 'https'.
aliases: docker_url |
files
|
|
List of file names relative to
project_src . Overrides docker-compose.yml or docker-compose.yaml.Files are loaded and merged in the order given.
|
hostname_check
|
|
Whether or not to check the Docker daemon's hostname against the name provided in the client certificate.
|
key_path
|
|
Path to the client's TLS key file.
aliases: tls_client_key |
nocache
(added in 2.2) |
|
Use with the build option to ignore the cache during the image build process.
|
project_name
|
|
Provide a project name. If not provided, the project name is taken from the basename of
project_src .Required when
definition is provided. |
project_src
|
|
Path to a directory containing a docker-compose.yml or docker-compose.yaml file.
Mutually exclusive with
definition .Required when no
definition is provided. |
pull
(added in 2.2) |
|
Use with state present to always pull images prior to starting the application.
Same as running docker-compose pull.
When a new image is pulled, services using the image will be recreated unless
recreate is never. |
recreate
|
|
By default containers will be recreated when their configuration differs from the service definition.
Setting to never ignores configuration differences and leaves existing containers unchanged.
Setting to always forces recreation of all existing containers.
|
remove_images
|
|
Use with state absent to remove the all images or only local images.
|
remove_volumes
|
|
Use with state absent to remove data volumes.
|
restarted
|
|
Use with state present to restart all containers.
|
scale
|
|
When
state is present scale services. Provide a dictionary of key/value pairs where the key is the name of the service and the value is an integer count for the number of containers. |
services
|
|
When
state is present run docker-compose up on a subset of services. |
ssl_version
|
Default:
1.0
|
Provide a valid SSL version number. Default value determined by docker-py, currently 1.0.
|
state
|
|
Desired state of the project.
Specifying present is the same as running docker-compose up.
Specifying absent is the same as running docker-compose down.
|
stopped
|
|
Use with state present to leave the containers in an exited or non-running state.
|
timeout
|
Default:
60
|
The maximum amount of time in seconds to wait on a response from the API.
|
tls
|
|
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server.
|
tls_hostname
|
Default:
localhost
|
When verifying the authenticity of the Docker Host server, provide the expected name of the server.
|
tls_verify
|
|
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server.
|
Note
# Examples use the django example at U(https://docs.docker.com/compose/django/). Follow it to create the flask
# directory
- name: Run using a project directory
hosts: localhost
connection: local
gather_facts: no
tasks:
- docker_service:
project_src: flask
state: absent
- docker_service:
project_src: flask
register: output
- debug:
var: output
- docker_service:
project_src: flask
build: no
register: output
- debug:
var: output
- assert:
that: "not output.changed "
- docker_service:
project_src: flask
build: no
stopped: true
register: output
- debug:
var: output
- assert:
that:
- "not web.flask_web_1.state.running"
- "not db.flask_db_1.state.running"
- docker_service:
project_src: flask
build: no
restarted: true
register: output
- debug:
var: output
- assert:
that:
- "web.flask_web_1.state.running"
- "db.flask_db_1.state.running"
- name: Scale the web service to 2
hosts: localhost
connection: local
gather_facts: no
tasks:
- docker_service:
project_src: flask
scale:
web: 2
register: output
- debug:
var: output
- name: Run with inline v2 compose
hosts: localhost
connection: local
gather_facts: no
tasks:
- docker_service:
project_src: flask
state: absent
- docker_service:
project_name: flask
definition:
version: '2'
services:
db:
image: postgres
web:
build: "{{ playbook_dir }}/flask"
command: "python manage.py runserver 0.0.0.0:8000"
volumes:
- "{{ playbook_dir }}/flask:/code"
ports:
- "8000:8000"
depends_on:
- db
register: output
- debug:
var: output
- assert:
that:
- "web.flask_web_1.state.running"
- "db.flask_db_1.state.running"
- name: Run with inline v1 compose
hosts: localhost
connection: local
gather_facts: no
tasks:
- docker_service:
project_src: flask
state: absent
- docker_service:
project_name: flask
definition:
db:
image: postgres
web:
build: "{{ playbook_dir }}/flask"
command: "python manage.py runserver 0.0.0.0:8000"
volumes:
- "{{ playbook_dir }}/flask:/code"
ports:
- "8000:8000"
links:
- db
register: output
- debug:
var: output
- assert:
that:
- "web.flask_web_1.state.running"
- "db.flask_db_1.state.running"
Common return values are documented here, the following are the fields unique to this module:
Key |
Returned |
Description |
---|---|---|
actions
complex
|
when in check mode or debug true |
Provides the actions to be taken on each service as determined by compose.
|
service_name
complex
|
always |
Name of the service.
|
action
list
|
always |
A descriptive name of the action to be performed on the service's containers.
|
id
string
|
always |
the container's long ID
|
short_id
string
|
always |
the container's short ID
|
name
string
|
always |
the container's name
|
pulled_image
complex
|
on image pull |
Provides image details when a new image is pulled for the service.
|
name
string
|
always |
name of the image
|
id
string
|
always |
image hash
|
built_image
complex
|
on image build |
Provides image details when a new image is built for the service.
|
name
string
|
always |
name of the image
|
id
string
|
always |
image hash
|
service
complex
|
success |
Name of the service.
|
container_name
complex
|
success |
Name of the container. Format is project_service_#.
|
cmd
list
|
success |
One or more commands to be executed in the container.
|
image
str
|
success |
Name of the image from which the container was built.
|
labels
complex
|
success |
Meta data assigned to the container.
|
networks
complex
|
success |
Contains a dictionary for each network to which the container is a member.
|
macAddress
str
|
success |
Mac Address assigned to the virtual NIC.
|
globalIPv6PrefixLen
int
|
success |
IPv6 subnet length.
|
links
list
|
success |
List of container names to which this container is linked.
|
globalIPv6
str
|
success |
IPv6 address assigned to the container.
|
aliases
list
|
success |
Aliases assigned to the container by the network.
|
IPAddress
string
|
success |
The IP address assigned to the container.
|
IPPrefixLen
int
|
success |
Number of bits used by the subnet.
|
state
complex
|
success |
Information regarding the current disposition of the container.
|
status
str
|
success |
Description of the running state.
|
running
bool
|
success |
Whether or not the container is up with a running process.
|
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
Hint
If you notice any issues in this documentation you can edit this document to improve it.