execute tasks as user mastodon

This commit is contained in:
rene
2022-03-18 17:01:33 +01:00
parent 7427614056
commit 1fafdad7a3
3 changed files with 105 additions and 119 deletions

View File

@@ -1,100 +1,86 @@
- name: Clone mastodon
git:
repo: "https://github.com/mastodon/mastodon.git"
dest: "{{ mastodon_home }}/{{mastodon_path}}"
clone: true
- block:
become: true
become_user: "{{ mastodon_user }}"
# - name: Update to latest version
# shell: "git fetch; git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
# args:
# chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
- name: Clone mastodon
git:
repo: "https://github.com/mastodon/mastodon.git"
dest: "{{ mastodon_home }}/{{mastodon_path}}"
clone: true
- name: Bundle install
shell: |
~/.rbenv/shims/bundle config set --local deployment 'true' && \
~/.rbenv/shims/bundle config set --local without 'test' && \
~/.rbenv/shims/bundle config set --local with 'development' && \
~/.rbenv/shims/bundle install -j$(getconf _NPROCESSORS_ONLN)
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
# - name: Update to latest version
# shell: "git fetch; git checkout $(git tag -l | grep -v 'rc[1-9]*$' | sort -V | tail -n 1)"
# args:
# chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
- name: Yarn install
command: yarn install --pure-lockfile
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
- name: Bundle install
shell: |
~/.rbenv/shims/bundle config set --local deployment 'true' && \
~/.rbenv/shims/bundle config set --local without 'test' && \
~/.rbenv/shims/bundle config set --local with 'development' && \
~/.rbenv/shims/bundle install -j$(getconf _NPROCESSORS_ONLN)
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
- name: Yarn install
command: yarn install --pure-lockfile
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
- name: Media cleanup cronjob
cron:
name: "media cleanup"
minute: "15"
hour: "1"
job: '/bin/bash -c ''export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd {{ mastodon_home }}/{{ mastodon_path }} && RAILS_ENV=production ./bin/tootctl media remove'''
- stat: path={{ mastodon_home }}/{{ mastodon_path }}/.env.production
register: production_config
- name: Migrate database
shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails db:migrate"
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
when: production_config.stat.exists
- name: Precompile assets
shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails assets:precompile"
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
when: production_config.stat.exists
- name: Install systemd sidekiq Service Files
template:
src: mastodon-sidekiq.service.j2
dest: /etc/systemd/system/mastodon-sidekiq.service
become: true
become_user: root
- name: Install systemd web Service Files
template:
src: mastodon-web.service.j2
dest: /etc/systemd/system/mastodon-web.service
become: true
become_user: root
- name: Install systemd streaming Service Files
template:
src: mastodon-streaming.service.j2
dest: /etc/systemd/system/mastodon-streaming.service
become: true
become_user: root
- name: Media cleanup cronjob
cron:
name: "media cleanup"
minute: "15"
hour: "1"
job: '/bin/bash -c ''export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd {{ mastodon_home }}/{{ mastodon_path }} && RAILS_ENV=production ./bin/tootctl media remove'''
- stat: path={{ mastodon_home }}/{{ mastodon_path }}/.env.production
register: production_config
- name: Migrate database
shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails db:migrate"
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
when: production_config.stat.exists
- name: Precompile assets
shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails assets:precompile"
args:
chdir: "{{ mastodon_home }}/{{ mastodon_path }}"
when: production_config.stat.exists
- name: Enable mastodon-web
command: systemctl enable mastodon-web.service
become: true
become_user: root
- name: Enable mastodon-streaming
command: systemctl enable mastodon-streaming.service
become: true
become_user: root
- name: Enable mastodon-sidekiq
command: systemctl enable mastodon-sidekiq.service
become: true
become_user: root
- name: Restart mastodon-web
command: systemctl restart mastodon-web.service
when: production_config.stat.exists
become: true
become_user: root
- name: Restart mastodon-streaming
command: systemctl restart mastodon-streaming.service
when: production_config.stat.exists
become: true
become_user: root
- name: Restart mastodon-sidekiq
command: systemctl restart mastodon-sidekiq.service
when: production_config.stat.exists
become: true
become_user: root
when: production_config.stat.exists