Created
June 7, 2016 17:54
-
-
Save amit-naudiyal/5fc4c1e3ee918632800fd9b417cfc9fc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ansible-playbook | |
--- | |
- name: run mezzanine from containers | |
hosts: localhost | |
vars_files: | |
- secrets.yml | |
vars: | |
# The postgres container uses the same name for the database | |
# and the user | |
database_name: mezzanine | |
database_user: mezzanine | |
database_port: 5432 | |
gunicorn_port: 8000 | |
docker_host: "{{ lookup('env', 'DOCKER_HOST') | | |
regex_replace('^tcp://(.*):\\d+$', '\\\\1') | default('localhost', true) }}" | |
project_dir: /srv/project | |
website_domain: "{{ docker_host }}.xip.io" | |
mezzanine_env: | |
SECRET_KEY: "{{ secret_key }}" | |
NEVERCACHE_KEY: "{{ nevercache_key }}" | |
ALLOWED_HOSTS: "*" | |
DATABASE_NAME: "{{ database_name }}" | |
DATABASE_USER: "{{ database_user }}" | |
DATABASE_PASSWORD: "{{ database_password }}" | |
DATABASE_HOST: "{{ database_host }}" | |
DATABASE_PORT: "{{ database_port }}" | |
GUNICORN_PORT: "{{ gunicorn_port }}" | |
setadmin_env: | |
PROJECT_DIR: "{{ project_dir }}" | |
ADMIN_PASSWORD: "{{ admin_password }}" | |
setsite_env: | |
PROJECT_DIR: "{{ project_dir }}" | |
WEBSITE_DOMAIN: "{{ website_domain }}" | |
tasks: | |
- name: start the postgres container | |
docker: | |
image: postgres:9.4 | |
name: postgres | |
publish_all_ports: True | |
env: | |
POSTGRES_USER: "{{ database_user }}" | |
POSTGRES_PASSWORD: "{{ database_password }}" | |
- name: capture database ip address and mapped port | |
set_fact: | |
database_host: "{{ docker_containers[0].NetworkSettings.IPAddress }}" | |
mapped_database_port: "{{ docker_containers[0].NetworkSettings.Ports[ | |
'5432/tcp'][0].HostPort}}" | |
- name: wait for database to come up | |
wait_for: host={{ docker_host }} port={{ mapped_database_port }} | |
- name: initialize database | |
docker: | |
image: lorin/mezzanine:latest | |
command: python manage.py {{ item }} --noinput | |
wait: True | |
env: "{{ mezzanine_env }}" | |
with_items: | |
- syncdb | |
- migrate | |
register: django | |
- name: set the site id | |
docker: | |
image: lorin/mezzanine:latest | |
command: /srv/scripts/setsite.py | |
env: "{{ setsite_env.update(mezzanine_env) }}{{ setsite_env }}" | |
wait: yes | |
- name: set the admin password | |
docker: | |
image: lorin/mezzanine:latest | |
command: /srv/scripts/setadmin.py | |
env: "{{ setadmin_env.update(mezzanine_env) }}{{ setadmin_env }}" | |
wait: yes | |
- name: start the memcached container | |
docker: | |
image: lorin/memcached:latest | |
name: memcached | |
- name: start the mezzanine container | |
docker: | |
image: lorin/mezzanine:latest | |
name: mezzanine | |
env: "{{ mezzanine_env }}" | |
links: memcached | |
- name: start the mezzanine cron job | |
docker: | |
image: lorin/mezzanine:latest | |
name: mezzanine | |
env: "{{ mezzanine_env }}" | |
command: cron -f | |
- name: start the cert container | |
docker: | |
image: lorin/certs:latest | |
name: certs | |
- name: run nginx | |
docker: | |
image: lorin/nginx-mezzanine:latest | |
ports: | |
- 80:80 | |
- 443:443 | |
name: nginx | |
volumes_from: | |
- mezzanine | |
- certs | |
links: mezzanine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment