Ansible Phoenix deployment playbook
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
--- | |
# 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