Created
March 19, 2015 22:32
-
-
Save Zolmeister/aa0cf06678170a39c3c0 to your computer and use it in GitHub Desktop.
Ansible Skeleton
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
--- | |
# file: roles/app/tasks/main.yml | |
- name: ensure logging directory exists | |
file: path=/var/log/acme state=directory | |
tags: | |
- install | |
- name: ensure config directory exists | |
file: path=/etc/acme/app state=directory | |
tags: | |
- install | |
- name: download image | |
shell: docker pull acme/app | |
tags: | |
- install | |
- name: copy environment config | |
template: src=../files/config.env dest=/etc/acme/app/config.env | |
tags: | |
- install | |
- update | |
- copy | |
# Must be run with --tags=install first, or this will hang forever | |
- name: Wait for backup server to be up | |
wait_for: host={{ ansible_ssh_host }} port={{ app_port + 1 }} state=started timeout=80 | |
tags: | |
- update | |
- name: update image | |
shell: docker pull acme/app | |
tags: | |
- update | |
- name: kill app | |
shell: docker stop app && docker rm app | |
tags: | |
- update | |
- rollback | |
- stop | |
- restart | |
- name: start app | |
shell: docker run | |
--restart on-failure | |
-v /var/log/acme:/var/log/acme | |
-p {{ app_port }}:{{ app_port }} | |
--env-file=/etc/acme/app/config.env | |
--name app | |
-d | |
-t acme/app:{{ version | default('latest') }} | |
tags: | |
- update | |
- rollback | |
- start | |
- restart | |
- name: Wait for main server to be up | |
wait_for: host={{ ansible_ssh_host }} port={{ app_port }} state=started timeout=80 | |
tags: | |
- update | |
- rollback | |
- name: kill app backup | |
shell: docker stop app-backup && docker rm app-backup | |
tags: | |
- update | |
- rollback | |
- stop-backup | |
- restart-backup | |
- name: start app backup | |
shell: docker run | |
--restart on-failure | |
-v /var/log/acme:/var/log/acme | |
-p {{ app_port + 1 }}:{{ app_port }} | |
--env-file=/etc/acme/app/config.env | |
--name app-backup | |
-d | |
-t acme/app:{{ version | default('latest') }} | |
tags: | |
- update | |
- rollback | |
- start-backup | |
- restart-backup |
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
--- | |
# file: roles/docker/tasks/main.yml | |
- name: add docker apt key | |
apt_key: keyserver=hkp://keyserver.ubuntu.com:80 id=36A1D7869245C8950F966E92D8576A8BA88D21E9 | |
- name: add docker apt repo | |
apt_repository: repo='deb https://get.docker.io/ubuntu docker main' | |
- name: update apt and install docker | |
apt: name=lxc-docker update_cache=yes | |
- name: install pip | |
apt: name=python-pip | |
- name: fix pip, because for some reason its broken on apt | |
shell: easy_install -U pip | |
- name: pip install docker-py | |
pip: name=docker-py | |
- name: login to registry | |
shell: docker login -u USERNAME -p PASSWORD -e [email protected] | |
# Will error if no dangling containers | |
- name: clean up docker containers | |
shell: docker rm $(docker ps -aq) | |
ignore_errors: yes | |
tags: | |
- update | |
# Will error if no dangling images | |
- name: clean up docker images | |
shell: docker rmi $(docker images -f "dangling=true" -q) | |
ignore_errors: yes | |
tags: | |
- update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment