From 4b31dbc90a77f411966b5a6c34cbbcba405a13af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Tue, 30 Jul 2024 16:18:03 +0200 Subject: [PATCH] [mod] role:mastodon --- roles/mastodon/defaults/main.json | 4 + roles/mastodon/tasks/main.json | 169 ++++++++++++++++++++++++++++++ roles/mastodon/vardef.json | 10 ++ 3 files changed, 183 insertions(+) create mode 100644 roles/mastodon/defaults/main.json create mode 100644 roles/mastodon/tasks/main.json create mode 100644 roles/mastodon/vardef.json diff --git a/roles/mastodon/defaults/main.json b/roles/mastodon/defaults/main.json new file mode 100644 index 0000000..dd361be --- /dev/null +++ b/roles/mastodon/defaults/main.json @@ -0,0 +1,4 @@ +{ + "var_mastodon_user": "mastodon", + "var_mastodon_directory": "/opt/mastodon" +} diff --git a/roles/mastodon/tasks/main.json b/roles/mastodon/tasks/main.json new file mode 100644 index 0000000..ae08a4c --- /dev/null +++ b/roles/mastodon/tasks/main.json @@ -0,0 +1,169 @@ +[ + { + "name": "packages", + "become": true, + "ansible.builtin.apt": { + "update_cache": true, + "pkg": [ + "curl", + "wget", + "gnupg", + "apt-transport-https", + "lsb-release", + "ca-certificates", + "imagemagick", + "ffmpeg", + "libpq-dev", + "libxml2-dev", + "libxslt1-dev", + "file", + "git-core", + "g++", + "libprotobuf-dev", + "protobuf-compiler", + "pkg-config", + "gcc", + "autoconf", + "bison", + "build-essential", + "libssl-dev", + "libyaml-dev", + "libreadline6-dev", + "zlib1g-dev", + "libncurses5-dev", + "libffi-dev", + "libgdbm-dev", + "nginx", + "nodejs", + "redis-server", + "redis-tools", + "postgresql", + "postgresql-contrib", + "certbot", + "python3-certbot-nginx", + "libidn11-dev", + "libicu-dev", + "libjemalloc-dev" + ] + } + }, + { + "name": "user", + "become": true, + "ansible.builtin.user": { + "name": "{{var_mastodon_user}}", + "create_home": true, + "home": "{{var_mastodon_directory}}" + } + }, + { + "name": "ruby_environment | 1", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "git clone https://github.com/rbenv/rbenv.git ~/.rbenv" + } + }, + { + "name": "ruby_environment | 2", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bashrc" + } + }, + { + "name": "ruby_environment | 3", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "echo 'eval \"$(rbenv init -)\"' >> ~/.bashrc" + } + }, + { + "name": "ruby_environment | 4", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "bash 'git clone https://github.com/rbenv/ruby-build.git \"$(rbenv root)\"/plugins/ruby-build'" + } + }, + { + "name": "ruby_environment | 5", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "RUBY_CONFIGURE_OPTS='--with-jemalloc rbenv install 3.2.3' rbenv global 3.2.3" + } + }, + { + "name": "ruby_environment | 6", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "gem install bundler --no-document" + } + }, + { + "name": "setup | 1", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "cmd": "git clone https://github.com/mastodon/mastodon.git live" + } + }, + { + "name": "setup | 2", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "git checkout $(git tag -l | grep '^v[0-9.]*$' | sort -V | tail -n 1)" + } + }, + { + "name": "setup | 3", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "bundle config deployment 'true'" + } + }, + { + "name": "setup | 4", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "bundle config without 'development test'" + } + }, + { + "name": "setup | 5", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "bundle install -j$(getconf _NPROCESSORS_ONLN)" + } + }, + { + "name": "setup | 6", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "yarn install --pure-lockfile" + } + }, + { + "name": "setup | 7", + "become": true, + "become_user": "{{var_mastodon_user}}", + "ansible.builtin.command": { + "chdir": "{{var_mastodon_directory}}/live", + "cmd": "RAILS_ENV=production bundle exec rake mastodon:setup" + } + } +] diff --git a/roles/mastodon/vardef.json b/roles/mastodon/vardef.json new file mode 100644 index 0000000..a342bb5 --- /dev/null +++ b/roles/mastodon/vardef.json @@ -0,0 +1,10 @@ +{ + "user": { + "mandatory": false, + "type": "string" + }, + "directory": { + "mandatory": false, + "type": "string" + } +}