Skip to content

Instantly share code, notes, and snippets.

@tfwright
Last active May 12, 2023 09:18
Show Gist options
  • Save tfwright/b7e6a2c8be66db576404e0b9a1413a75 to your computer and use it in GitHub Desktop.
Save tfwright/b7e6a2c8be66db576404e0b9a1413a75 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