Created
July 5, 2016 12:09
-
-
Save bergerx/5aa6f6805a62864556984317c9cd901c to your computer and use it in GitHub Desktop.
A sample for managing containers on ubuntu using ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: prepare calico-node upstart service file | |
template: src=roles/docker/templates/upstart-docker-instance.j2.j2 dest="/etc/init/{{ item.service_name }}.conf" | |
tags: | |
- service | |
- calico | |
with_items: | |
- service_name: calico-node | |
docker_name: calico-node | |
docker_run: > | |
/usr/bin/docker run --rm \ | |
--name=calico-node \ | |
--net=host \ | |
--privileged \ | |
--name=calico-node \ | |
-e HOSTNAME={{ ansible_hostname }} \ | |
-e CALICO_NETWORKING=true \ | |
-e ETCD_AUTHORITY={{ host_ip }}:2379 \ | |
-e ETCD_SCHEME=http \ | |
-e IP={{ host_ip }} \ | |
-v /var/log/calico:/var/log/calico \ | |
-v /lib/modules:/lib/modules \ | |
-v /var/run/calico:/var/run/calico \ | |
calico/node:v0.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "{{ item.service_name }} container" | |
start on started docker | |
respawn | |
pre-start script | |
# node containers fail to auto-start on docker service restart without this | |
FILE=/var/run/docker.sock | |
while [ ! -S $FILE ] ; do | |
inotifywait -t 2 -e create $(dirname $FILE) | |
done | |
docker rm -f {{ item.docker_name }} &>/dev/null || : | |
end script | |
script | |
exec {{ item.docker_run }} | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment