ansible-roles/webapps/mastodon/tasks/upgrade.yml
Mathieu Gauthier-Pilote 1b6527c4ce
All checks were successful
gitea/ansible-roles/pipeline/head This commit looks good
With post-deployement the 2nd time; allow to upgrade rbenv if needed; upgrade browsers list db to remove warnings
2023-04-06 14:46:01 -04:00

99 lines
2.7 KiB
YAML

---
# tasks file for mastodon upgrade
- name: Dump database to a file with compression
postgresql_db:
name: "{{ service }}_production"
state: dump
target: "~/{{ service }}_production.sql.gz"
become_user: postgres
- name: Install Ruby for service user (rbenv)
include_role:
name: rbenv
vars:
- username: "{{ service }}"
- rbenv_ruby_version: "{{ ruby_version }}"
- name: Checkout (git)
git:
repo: "{{ git_url }}"
dest: "~/mastodon/"
version: "{{ git_version | default(omit) }}"
force: yes
update: yes
become_user: "{{ service }}"
- block:
- name: Install bundler
shell: ". ~/.profile && gem install bundler --no-document"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Install gem dependencies
shell: ". ~/.profile && bundle install --deployment --without development test -j{{ ansible_processor_count }}"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Install javascript dependencies
shell: ". ~/.profile && yarn install --pure-lockfile"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Upgrade browsers list db
shell: ". ~/.profile && npx update-browserslist-db@latest"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Run database migrations, skipping post-deployment
shell: ". ~/.profile && SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Precompile assets
shell: ". ~/.profile && RAILS_ENV=production bundle exec rails assets:precompile"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
- name: Adjust permissions of files in public folder
file:
path: "~/mastodon/public"
state: directory
mode: 'o=rX'
recurse: true
become_user: "{{ service }}"
- name: Restart services
service:
name: "{{ service }}.target"
state: restarted
- name: Run database migrations, this time including post-deployment
shell: ". ~/.profile && RAILS_ENV=production bundle exec rails db:migrate"
args:
chdir: "~/mastodon"
executable: /bin/bash # fails with /bin/sh
become_user: "{{ service }}"
- name: Restart services
service:
name: "{{ service }}.target"
state: restarted
- name: Define variable to skip next task by default
set_fact:
keep_db_dump: true
- name: Remove database dump
file:
path: "~/{{ service }}_production.sql.gz"
state: absent
become_user: postgres
when: keep_db_dump is undefined
tags: clean
- name: Reload nginx conf
service:
name: nginx
state: reloaded