ansible-role-mastodon/tasks/docker/docker.yml

231 lines
6.7 KiB
YAML

---
- name: Ensure docker configuration folder exists
file:
path: /etc/docker/
state: directory
- name: Configure docker daemon
copy:
dest: /etc/docker/daemon.json
content: "{{ docker_daemon_settings|to_json(indent=4, sort_keys=True) }}"
backup: true
- name: Configure docker service and reload it
systemd:
name: docker
state: reloaded
enabled: true
masked: false
# - name: Create Mastodon folder
# file:
# path: "{{ mastodon_composer_folder }}"
# state: directory
- name: Clon Mastodon repo
git:
repo: "{{ mastodon_repo }}"
dest: "{{ mastodon_composer_folder }}"
force: true
update: true
version: "{{ mastodon_version }}"
- name: Create docker-compose.yaml file
template:
src: templates/docker-compose.yml.j2
dest: "{{ mastodon_composer_folder }}/docker-compose.override.yml"
backup: true
- name: Ensure mastodon environment configuration is present
template:
src: templates/env.j2
dest: "{{ mastodon_composer_folder }}/.env.production"
mode: 0600
backup: true
- name: Generate secret key
shell: docker-compose run --rm web bundle exec rake secret
args:
chdir: "{{ mastodon_composer_folder }}"
register: secret_key_cmd
when: mastodon_secret_key_base == ''
- name: Set mastodon_secret_key_base
set_fact:
mastodon_secret_key_base: "{{ secret_key_cmd.stdout }}"
when: mastodon_secret_key_base == ''
- name: Add secret key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "SECRET_KEY_BASE={{ mastodon_secret_key_base }}"
regexp: "^SECRET_KEY_BASE="
backup: true
mode: 0600
- name: Generate OTP secret key
shell: docker-compose run --rm web bundle exec rake secret
args:
chdir: "{{ mastodon_composer_folder }}"
register: otp_key_cmd
when: mastodon_otp_secret == ''
- name: Set mastodon_otp_secret
set_fact:
mastodon_otp_secret: "{{ otp_key_cmd.stdout }}"
when: mastodon_otp_secret == ''
- name: Add OTP key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "OTP_SECRET={{ mastodon_otp_secret }}"
regexp: "^OTP_SECRET="
backup: true
mode: 0600
- name: Generate Paperclip secret key
shell: docker-compose run --rm web bundle exec rake secret
args:
chdir: "{{ mastodon_composer_folder }}"
register: paperclip_key_cmd
when: mastodon_paperclip_secret == ''
- name: Set mastodon_paperclip_secret
set_fact:
mastodon_paperclip_secret: "{{ otppaperclip_key_cmd_key_cmd.stdout }}"
when: mastodon_paperclip_secret == ''
- name: Add Paperclip key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "PAPERCLIP_SECRET={{ mastodon_paperclip_secret }}"
regexp: "^PAPERCLIP_SECRET="
backup: true
mode: 0600
- name: Generate VAPID keypair
shell: 'docker-compose run --rm web bundle exec rake mastodon:webpush:generate_vapid_key'
args:
chdir: "{{ mastodon_composer_folder }}"
register: vapid_key_cmd
when: vapid_public_key == ''
- name: Set vapid_public_key
set_fact:
vapid_public_key: "{{ vapid_key_cmd.stdout_lines[1] }}"
when: vapid_public_key == ''
- name: Set vapid_private_key
set_fact:
vapid_private_key: "{{ vapid_key_cmd.stdout_lines[0] }}"
when: vapid_private_key == ''
- name: Add Paperclip private key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "{{ vapid_private_key }}"
regexp: "^VAPID_PRIVATE_KEY="
mode: 0600
backup: true
- name: Add Paperclip public key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "{{ vapid_public_key }}"
regexp: "^VAPID_PUBLIC_KEY="
mode: 0600
backup: true
- name: Build Mastodon container to include secrets
community.docker.docker_compose:
project_name: mastodon
project_src: "{{ mastodon_composer_folder }}/"
state: present
stopped: true
build: true
# CREATE USER mastodon CREATEDB;
- name: Set up database
shell: "docker-compose run --rm web bundle exec rake db:setup && echo 'Database ready' > /var/lib/mastodon_db_setup"
args:
creates: /var/lib/mastodon_db_setup
chdir: "{{ mastodon_composer_folder }}"
when: mastodon_initial_setup
- name: Migrate database
shell: "docker-compose run --rm web bundle exec rake db:migrate && echo 'Database migrated' > /var/lib/mastodon_db_migrated"
args:
creates: /var/lib/mastodon_db_migrated
chdir: "{{ mastodon_composer_folder }}"
when: not mastodon_initial_setup
- name: Create initial user
shell: "docker-compose run --rm web bin/tootctl accounts create '{{ mastodon_owner }}' --email '{{ mastodon_owner_email }}' --confirmed --role Owner && echo 'Owner account created' > /var/lib/mastodon_owner_created"
args:
creates: /var/lib/mastodon_owner_created
chdir: "{{ mastodon_composer_folder }}"
register: owner_result
when: mastodon_initial_setup
- name: Show owner password
debug:
var: owner_result
when: mastodon_initial_setup
- name: Deploy Mastodon systemd service unit
template:
src: templates/mastodon.service.j2
dest: /etc/systemd/system/mastodon.service
backup: true
- name: Deploy Mastodon Media Remove systemd service unit
template:
src: templates/mastodon-media-remove.service.j2
dest: /etc/systemd/system/mastodon-media-remove.service
backup: true
- name: Deploy Mastodon Media Remove systemd timer unit
template:
src: templates/mastodon-media-remove.timer.j2
dest: /etc/systemd/system/mastodon-media-remove.timer
backup: true
- name: Deploy Mastodon Preview Cards Remove systemd service unit
template:
src: templates/mastodon-preview_cards-remove.service.j2
dest: /etc/systemd/system/mastodon-preview_cards-remove.service
backup: true
- name: Deploy Mastodon Preview Cards Remove systemd timer unit
template:
src: templates/mastodon-preview_cards-remove.timer.j2
dest: /etc/systemd/system/mastodon-preview_cards-remove.timer
backup: true
- name: Deploy Mastodon Search Deploy systemd service unit
template:
src: templates/mastodon-search-deploy.service.j2
dest: /etc/systemd/system/mastodon-search-deploy.service
backup: true
- name: Deploy Mastodon Search Deploy systemd timer unit
template:
src: templates/mastodon-search-deploy.timer.j2
dest: /etc/systemd/system/mastodon-search-deploy.timer
backup: true
- name: Enable Mastodon Media Remove systemd timer unit
systemd:
name: mastodon-media-remove.timer
state: started
enabled: true
daemon_reload: true
- name: Enable Mastodon systemd timer units
systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- mastodon-preview_cards-remove.timer
- mastodon-search-deploy.timer