Skip to content

Instantly share code, notes, and snippets.

@inoas
Forked from tfwright/deploy.yml
Created November 23, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inoas/0b4136ab464afbd985bd5760ffe0b816 to your computer and use it in GitHub Desktop.
Save inoas/0b4136ab464afbd985bd5760ffe0b816 to your computer and use it in GitHub Desktop.
Ansible Phoenix deployment playbook
---
# ansible 2.9.0
- name: Deploy to production
hosts: production
remote_user: user
vars:
app_root: /home/user/apps/my_app
tasks:
- name: Initialize the deploy directory
deploy_helper:
path: '{{ app_root }}'
- name: Clone the project to the new release folder
git:
repo: git@github.com:me/my_app.git
dest: '{{ deploy_helper.new_release_path }}'
version: master
- name: Add an unfinished file, to allow cleanup on successful finalize
file:
path: '{{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }}'
state: touch
- name: Build release
shell:
cmd: '{{ item }}'
chdir: '{{ deploy_helper.new_release_path }}/'
with_items:
- mix deps.get --only prod
- export $(cat {{ deploy_helper.shared_path }}/environment | xargs) && mix release
environment:
PATH: "{{ ansible_env.PATH }}:/home/deployer/.asdf/shims"
- name: Migrate app
shell:
cmd: '{{ deploy_helper.new_release_path }}/_build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"'
- name: Finalize the deploy, removing the unfinished file and switching the symlink
deploy_helper:
path: '{{ app_root }}'
release: '{{ deploy_helper.new_release }}'
state: finalize
- name: Restart app
systemd:
name: my_app
state: restarted
become: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment