Use rancher-compose
from
Ansible. This repository defines an
Ansible module called
rancher_compose
which is designed to allow the management of
Rancher stacks in a
Rancher environment.
It does this by invoking the rancher-compose
tool.
Download and save the module file rancher_compose.py
to a directory Ansible
recognises as being a module library path. This directory can be:
-
The default library path specified by your Ansible installation.
-
A path specified by the
--module-path
option to either theansible
oransible-playbook
commands. -
A path defined in the
ANSIBLE_LIBRARY
environment variable. -
A directory called
library
that resides alongside your top level playbooks. -
A directory defined in the
library
parameter within youransible.cfg
file.
Unless a docker-compose.yml
file is specified in the COMPOSE_FILE
environment variable then rancher_compose
requires that the docker_compose
option point to a docker-compose.yml
file. Unless provided by the appropriate
environment variables, the url
, access_key
and secret_key
options must
also be defined. Note that environment variables can be defined in the file
pointed to by the env_file
option.
The Rancher stack is manipulated by setting the state
option
appropriately. e.g.:
# Create a stack
- rancher_compose:
docker_compose: "{{playbook_dir}}/docker-compose.yml"
url: http://rancher-server:8080
access_key: 62883FB58840FB83D016
secret_key: BCZLqYsrmbxnw4jR6e7iy56cb9qViWayq7Yhnw9C
state: present
# Update a stack
- rancher_compose:
docker_compose: "{{playbook_dir}}/docker-compose.yml"
url: http://rancher-server:8080
access_key: 62883FB58840FB83D016
secret_key: BCZLqYsrmbxnw4jR6e7iy56cb9qViWayq7Yhnw9C
state: reloaded
# Delete a stack
- rancher_compose:
docker_compose: "{{playbook_dir}}/docker-compose.yml"
url: http://rancher-server:8080
access_key: 62883FB58840FB83D016
secret_key: BCZLqYsrmbxnw4jR6e7iy56cb9qViWayq7Yhnw9C
state: absent
# Start a stack assuming appropriate environment variables have been set (see
# `rancher-compose --help` for details of environment variables).
- rancher_compose:
state: started
# Start a stack assuming appropriate environment variables are in the file
# `env-vars.txt`
- rancher_compose:
env_file: ./env-vars.txt
state: started
Note that you can also use Ansible's environment
keyword to set environment
variables which are made available for
variable interpolation
in rancher-compose.yml
and docker-compose.yml
files e.g running:
- rancher_compose:
docker_compose: "/tmp/docker-compose.yml"
url: http://rancher-server:8080
access_key: 62883FB58840FB83D016
secret_key: BCZLqYsrmbxnw4jR6e7iy56cb9qViWayq7Yhnw9C
state: present
environment:
IMAGE_TAG: 14.04
with the contents of /tmp/docker-compose.yml
as follows:
ubuntu:
tty: true
image: ubuntu:$IMAGE_TAG
stdin_open: true
would ensure that the ubuntu
service is deployed with an ubuntu:14.04
image.
GPL version 3
Homme Zwaagstra hrz@geodata.soton.ac.uk