Skip to main content

The obscene docker-compose deploy with ansible cli

Project description

Deploying a docker-compose.yml

Provide ssh configuration and target dir as first argument, then the path to a docker-compose.yml file:

ansible-compose user@host:22/absolute/target/path ./docker-compose-example.yml

Or, deploy from a url, just like kubectl apply would let you:

ansible-compose user@host:22/absolute/target/path https://raw.git.../docker-compose.yml

Automatic creation of volume dirs

It will try to automatically create the volume bind dirs for you. To set the uid and/or guid, set them as env vars, either in the compose.yml:

  uid: 1001
  gid: 100

Or with an env var:


Transforms for docker-compose.yml on the CLI

Transforms apply on the docker-compose.yml as if it was a template we are going to render using environment variables.

The best source of documentation for this feature is the test script.

with env vars: servicename_environment_something=foo will overwrite the something env var of the servicename service with the foo value, whereas setting drop_servicename_environment_something=1 will drop the value at all.

This kind of filter will also work on service options ie. servicename_image=foo or drop_servicename_image=1 would respectively override and drop the image key of the servicename service. It also works on services themselves, and any other key at the first level of the compose document.

Note that any other argument will be passed to ansible-playbook.

Running commands on the compose of a target

Provide ssh configuration and target dir as first argument, then the docker-compose command:

ansible-compose user@host:22/absolute/target/path stop
ansible-compose user@host:22/absolute/target/path start
ansible-compose user@host:22/absolute/target/path logs
ansible-compose user@host:22/absolute/target/path help



pip install --user ansible-compose
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

The current configuration in CI for image yourlabs/ansible-compose is:

  • SSH_PRIVATE_KEY=our passwordless private key generated with ssh-keygen -t ed25519 and default options
  • SSH_INSECURE=true not checking any host key today !

Example gitlab ci job

   stage: deploy
   image: yourlabs/ansible-compose
   - ansible-compose
         # composed to rely on $CI_COMMIT_SHA

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ansible-compose, version 0.1.4.post7
Filename, size File type Python version Upload date Hashes
Filename, size ansible-compose-0.1.4.post7.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page