From 43395ee775435c9de2bc46212c522ea1782b444f Mon Sep 17 00:00:00 2001 From: Simonas Kareiva Date: Tue, 3 Feb 2026 10:52:11 +0200 Subject: [PATCH] Deploy mastodon v0.1 --- .gitignore | 1 + ansible-navigator.yml | 8 +++ ansible.cfg | 6 ++ inventory | 1 + requirements.yml | 4 ++ roles/infra/README.md | 38 +++++++++++++ roles/infra/defaults/main.yml | 9 +++ roles/infra/handlers/main.yml | 3 + roles/infra/meta/main.yml | 36 ++++++++++++ roles/infra/tasks/git.yml | 46 ++++++++++++++++ roles/infra/tasks/main.yml | 9 +++ roles/infra/tasks/traefik.yml | 54 ++++++++++++++++++ roles/infra/vars/main.yml | 3 + roles/mastodon/README.md | 38 +++++++++++++ roles/mastodon/defaults/main.yml | 3 + roles/mastodon/handlers/main.yml | 3 + roles/mastodon/meta/main.yml | 35 ++++++++++++ roles/mastodon/tasks/db.yml | 30 ++++++++++ roles/mastodon/tasks/elasticsearch.yml | 31 +++++++++++ roles/mastodon/tasks/main.yml | 39 +++++++++++++ roles/mastodon/tasks/redis.yml | 22 ++++++++ roles/mastodon/tasks/sidekiq.yml | 48 ++++++++++++++++ roles/mastodon/tasks/web.yml | 64 ++++++++++++++++++++++ roles/mastodon/vars/db.yml | 9 +++ roles/mastodon/vars/main.yml | 19 +++++++ roles/mastodon/vars/smtp.yml | 12 ++++ roles/mastodon/vars/web.yml | 30 ++++++++++ roles/podman/README.md | 38 +++++++++++++ roles/podman/defaults/main.yml | 3 + roles/podman/handlers/main.yml | 7 +++ roles/podman/meta/main.yml | 36 ++++++++++++ roles/podman/tasks/main.yml | 76 ++++++++++++++++++++++++++ roles/podman/vars/main.yml | 19 +++++++ site.yml | 14 +++++ 34 files changed, 794 insertions(+) create mode 100644 .gitignore create mode 100644 ansible-navigator.yml create mode 100644 ansible.cfg create mode 100644 inventory create mode 100644 requirements.yml create mode 100644 roles/infra/README.md create mode 100644 roles/infra/defaults/main.yml create mode 100644 roles/infra/handlers/main.yml create mode 100644 roles/infra/meta/main.yml create mode 100644 roles/infra/tasks/git.yml create mode 100644 roles/infra/tasks/main.yml create mode 100644 roles/infra/tasks/traefik.yml create mode 100644 roles/infra/vars/main.yml create mode 100644 roles/mastodon/README.md create mode 100644 roles/mastodon/defaults/main.yml create mode 100644 roles/mastodon/handlers/main.yml create mode 100644 roles/mastodon/meta/main.yml create mode 100644 roles/mastodon/tasks/db.yml create mode 100644 roles/mastodon/tasks/elasticsearch.yml create mode 100644 roles/mastodon/tasks/main.yml create mode 100644 roles/mastodon/tasks/redis.yml create mode 100644 roles/mastodon/tasks/sidekiq.yml create mode 100644 roles/mastodon/tasks/web.yml create mode 100644 roles/mastodon/vars/db.yml create mode 100644 roles/mastodon/vars/main.yml create mode 100644 roles/mastodon/vars/smtp.yml create mode 100644 roles/mastodon/vars/web.yml create mode 100644 roles/podman/README.md create mode 100644 roles/podman/defaults/main.yml create mode 100644 roles/podman/handlers/main.yml create mode 100644 roles/podman/meta/main.yml create mode 100644 roles/podman/tasks/main.yml create mode 100644 roles/podman/vars/main.yml create mode 100644 site.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01a2417 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ansible-navigator.log diff --git a/ansible-navigator.yml b/ansible-navigator.yml new file mode 100644 index 0000000..0064335 --- /dev/null +++ b/ansible-navigator.yml @@ -0,0 +1,8 @@ +--- +ansible-navigator: + execution-environment: + pull: + policy: missing + mode: stdout + playbook-artifact: + enable: False diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..f1ad04c --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +remote_user = apps +become = false +inventory = inventory +pipelining = true +collections_path=./collections/:/usr/share/ansible/collections/ansible_collections \ No newline at end of file diff --git a/inventory b/inventory new file mode 100644 index 0000000..60c62c2 --- /dev/null +++ b/inventory @@ -0,0 +1 @@ +wtf.lt diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..b588a0a --- /dev/null +++ b/requirements.yml @@ -0,0 +1,4 @@ +--- +collections: + - name: containers.podman + - name: community.general \ No newline at end of file diff --git a/roles/infra/README.md b/roles/infra/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/infra/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/infra/defaults/main.yml b/roles/infra/defaults/main.yml new file mode 100644 index 0000000..27af5f5 --- /dev/null +++ b/roles/infra/defaults/main.yml @@ -0,0 +1,9 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for infra + +infra_acme: + storage: "acme.json" + email: "simonas@linux-lt.org" + +infra_htpasswd: "admin:$apr1$1I9ymeyT$Icf/hV7PLFzyW.I3uwfOR/" diff --git a/roles/infra/handlers/main.yml b/roles/infra/handlers/main.yml new file mode 100644 index 0000000..2520b22 --- /dev/null +++ b/roles/infra/handlers/main.yml @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: MIT-0 +--- +# handlers file for infra diff --git a/roles/infra/meta/main.yml b/roles/infra/meta/main.yml new file mode 100644 index 0000000..2695e2a --- /dev/null +++ b/roles/infra/meta/main.yml @@ -0,0 +1,36 @@ +--- +# SPDX-License-Identifier: MIT-0 +galaxy_info: + author: Simonas K. + description: infra for mastodon + company: wtf.lt + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/infra/tasks/git.yml b/roles/infra/tasks/git.yml new file mode 100644 index 0000000..4c90cd3 --- /dev/null +++ b/roles/infra/tasks/git.yml @@ -0,0 +1,46 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for git + +- name: Create git directory + ansible.builtin.file: + path: /home/apps/git + state: directory + +- name: Create main git container + containers.podman.podman_container: + name: gitea + image: docker.gitea.com/gitea:1.25.4 + env: + USER_UID: 1000 + USER_GID: 1000 + SSH_PORT: 222 + network: + - podman + volumes: + - "/home/apps/git:/data:z" + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "222:22" + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + label: + traefik.enable: "true" + traefik.http.routers.gitea.rule: "Host(`git.wtf.lt`)" + traefik.http.middlewares.gitea-https-redirect.redirectscheme.scheme: "https" + traefik.http.routers.gitea.middlewares: "gitea-https-redirect" + traefik.http.routers.gitea-secure.entrypoints: "https" + traefik.http.routers.gitea-secure.rule: "Host(`git.wtf.lt`)" + traefik.http.routers.gitea-secure.tls: "true" + traefik.http.routers.gitea-secure.tls.certresolver: "lets-encrypt" + traefik.http.services.gitea.loadbalancer.server.port: "3000" + +- name: Activate gitea container service + ansible.builtin.systemd_service: + name: container-gitea.service + state: started + enabled: true + scope: user diff --git a/roles/infra/tasks/main.yml b/roles/infra/tasks/main.yml new file mode 100644 index 0000000..6b30db5 --- /dev/null +++ b/roles/infra/tasks/main.yml @@ -0,0 +1,9 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for infra role + +- name: Install traefik + ansible.builtin.include_tasks: traefik.yml + +- name: Install gitea + ansible.builtin.include_tasks: git.yml diff --git a/roles/infra/tasks/traefik.yml b/roles/infra/tasks/traefik.yml new file mode 100644 index 0000000..ce41119 --- /dev/null +++ b/roles/infra/tasks/traefik.yml @@ -0,0 +1,54 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for traefik + +- name: Create acme file + ansible.builtin.file: + path: "~/{{ infra_acme.storage }}" + state: file + mode: "0600" + +- name: Setup local socket for traefik + ansible.builtin.systemd_service: + name: podman.socket + state: started + enabled: true + scope: user + +- name: Create main traefik container + containers.podman.podman_container: + name: traefik + image: docker.io/library/traefik:latest + ports: + - "80:80" + - "443:443" + - "8080:8080" + network: + - podman + security_opt: + - "label=type:container_runtime_t" + volumes: + - "/run/user/1000/podman/podman.sock:/var/run/docker.sock:z" + - "/home/apps/acme.json:/acme.json:z" + command: >- + --api.dashboard=true + --api.insecure=true + --certificatesresolvers.lets-encrypt.acme.email={{ infra_acme.email }} + --certificatesresolvers.lets-encrypt.acme.storage=/{{ infra_acme.storage }} + --certificatesresolvers.lets-encrypt.acme.tlschallenge=true + --entrypoints.http.address=:80 + --entrypoints.http.http.redirections.entryPoint.to=https + --entrypoints.http.http.redirections.entryPoint.scheme=https + --entrypoints.https.address=:443 + --providers.docker=true + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + +- name: Activate traefik container service + ansible.builtin.systemd_service: + name: container-traefik.service + state: started + enabled: true + scope: user diff --git a/roles/infra/vars/main.yml b/roles/infra/vars/main.yml new file mode 100644 index 0000000..46605c4 --- /dev/null +++ b/roles/infra/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for traefik diff --git a/roles/mastodon/README.md b/roles/mastodon/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/mastodon/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/mastodon/defaults/main.yml b/roles/mastodon/defaults/main.yml new file mode 100644 index 0000000..a5237d8 --- /dev/null +++ b/roles/mastodon/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for mastodon diff --git a/roles/mastodon/handlers/main.yml b/roles/mastodon/handlers/main.yml new file mode 100644 index 0000000..8b39e35 --- /dev/null +++ b/roles/mastodon/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for mastodon diff --git a/roles/mastodon/meta/main.yml b/roles/mastodon/meta/main.yml new file mode 100644 index 0000000..aac1a2b --- /dev/null +++ b/roles/mastodon/meta/main.yml @@ -0,0 +1,35 @@ +--- +# SPDX-License-Identifier: MIT-0 +galaxy_info: + author: Simonas K. + description: mastodon deployment + company: wtf.lt + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/mastodon/tasks/db.yml b/roles/mastodon/tasks/db.yml new file mode 100644 index 0000000..103c993 --- /dev/null +++ b/roles/mastodon/tasks/db.yml @@ -0,0 +1,30 @@ +--- +- name: Populate database variables + ansible.builtin.include_vars: + file: db.yml + +- name: Create DB instance for mastodon + containers.podman.podman_container: + name: database + image: docker.io/library/postgres:17 + network: + - "{{ mastodon_networks['mastodon_internal']['name'] }}" + env: + POSTGRES_DB: mastodon + POSTGRES_USER: "{{ mastodon_database.username }}" + POSTGRES_PASSWORD: "{{ mastodon_database.password }}" + volumes: + - "/home/apps/mastodon/postgresql:/var/lib/postgresql/data:Z" + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + force: true + healthcheck: "pg_isready -U postgres" + +- name: Activate database container service + ansible.builtin.systemd_service: + name: container-database.service + state: started + enabled: true + scope: user diff --git a/roles/mastodon/tasks/elasticsearch.yml b/roles/mastodon/tasks/elasticsearch.yml new file mode 100644 index 0000000..b005843 --- /dev/null +++ b/roles/mastodon/tasks/elasticsearch.yml @@ -0,0 +1,31 @@ +--- +- name: Create Elasticsearch instance for mastodon + containers.podman.podman_container: + name: elasticsearch + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.29 + network: + - "{{ mastodon_networks['mastodon_internal']['name'] }}" + - "{{ mastodon_networks['mastodon_external']['name'] }}" + volumes: + - "/home/apps/mastodon/elasticsearch:/usr/share/elasticsearch/data:Z" + env: + ES_JAVA_OPTS: "-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true" + xpack.license.self_generated.type: "basic" + xpack.security.enabled: "false" + xpack.watcher.enabled: "false" + xpack.graph.enabled: "false" + xpack.ml.enabled: "false" + bootstrap.memory_lock: "true" + cluster.name: "es-mastodon" + discovery.type: "single-node" + thread_pool.write.queue_size: "1000" + # generate_systemd: + # new: true + # restart_policy: "always" + # path: "~/.config/systemd/user/" + # force: true + restart_policy: "always" + healthcheck: "curl --silent --fail localhost:9200/_cluster/health || exit 1" + ulimit: + - "nofile=65536:65536" + - "memlock=-1:-1" diff --git a/roles/mastodon/tasks/main.yml b/roles/mastodon/tasks/main.yml new file mode 100644 index 0000000..de7200f --- /dev/null +++ b/roles/mastodon/tasks/main.yml @@ -0,0 +1,39 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for mastodon + +- name: Setup mastodon networks + containers.podman.podman_network: + name: "{{ item['key'] }}" + driver: "{{ item['value']['driver'] }}" + disable_dns: "{{ item['value']['disable_dns'] }}" + loop: "{{ mastodon_networks | dict2items }}" + +- name: Setup local directories + ansible.builtin.file: + name: "{{ item }}" + state: directory + loop: "{{ mastodon_local_dirs }}" + +- name: Populate active record variables + ansible.builtin.include_vars: + file: web.yml + +- name: Populate smtp variables + ansible.builtin.include_vars: + file: smtp.yml + +- name: Create database container instance + ansible.builtin.include_tasks: db.yml + +- name: Create redis container instance + ansible.builtin.include_tasks: redis.yml + +- name: Create elasticsearch container instance + ansible.builtin.include_tasks: elasticsearch.yml + +- name: Create web container instance + ansible.builtin.include_tasks: web.yml + +- name: Create sidekiq container instance + ansible.builtin.include_tasks: sidekiq.yml diff --git a/roles/mastodon/tasks/redis.yml b/roles/mastodon/tasks/redis.yml new file mode 100644 index 0000000..97cf338 --- /dev/null +++ b/roles/mastodon/tasks/redis.yml @@ -0,0 +1,22 @@ +--- +- name: Create Redis instance for mastodon + containers.podman.podman_container: + name: redis + image: docker.io/library/redis:7 + network: + - "{{ mastodon_networks['mastodon_internal']['name'] }}" + volumes: + - "/home/apps/mastodon/redis:/data:Z" + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + force: true + healthcheck: "redis-cli ping" + +- name: Activate elasticsearch container service + ansible.builtin.systemd_service: + name: container-redis.service + state: started + enabled: true + scope: user diff --git a/roles/mastodon/tasks/sidekiq.yml b/roles/mastodon/tasks/sidekiq.yml new file mode 100644 index 0000000..8ce776c --- /dev/null +++ b/roles/mastodon/tasks/sidekiq.yml @@ -0,0 +1,48 @@ +--- +# TODO: it's not idempotent +- name: Create Sidekiq instance of mastodon + containers.podman.podman_container: + name: sidekiq + image: ghcr.io/mastodon/mastodon:v4.5.5 + network: + - "{{ mastodon_networks['mastodon_internal']['name'] }}" + - "{{ mastodon_networks['mastodon_external']['name'] }}" + command: "bundle exec sidekiq" + env: + LOCAL_DOMAIN: "wtf.lt" + REDIS_HOST: redis + REDIS_PORT: 6379 + DB_HOST: database + DB_NAME: mastodon + DB_USER: "{{ mastodon_database.username }}" + DB_PASS: "{{ mastodon_database.password }}" + DB_PORT: 5432 + ES_ENABLED: true + ES_HOST: elasticsearch + ES_PORT: 9200 + ES_PRESET: single_node_cluster + ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: "{{ active_record_encryption.DETERMINISTIC_KEY }}" + ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: "{{ active_record_encryption.KEY_DERIVATION_SALT }}" + ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: "{{ active_record_encryption.PRIMARY_KEY }}" + SECRET_KEY_BASE: "{{ secret_key_base }}" + SMTP_SERVER: "{{ smtp.SERVER }}" + SMTP_PORT: "{{ smtp.PORT }}" + SMTP_LOGIN: "{{ smtp.LOGIN }}" + SMTP_PASSWORD: "{{ smtp.PASSWORD }}" + SMTP_FROM_ADDRESS: "{{ smtp.FROM_ADDRESS }}" + TRUSTED_PROXY_IP: "127.0.0.1/8,::1/128,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7" + volumes: + - "/home/apps/mastodon/system:/mastodon/public/system:z" + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + force: true + healthcheck: "ps aux | grep '[s]idekiq 8' || false" + +- name: Activate sidekiq container service + ansible.builtin.systemd_service: + name: container-sidekiq.service + state: started + enabled: true + scope: user diff --git a/roles/mastodon/tasks/web.yml b/roles/mastodon/tasks/web.yml new file mode 100644 index 0000000..4d889cb --- /dev/null +++ b/roles/mastodon/tasks/web.yml @@ -0,0 +1,64 @@ +--- +- name: Populate active record variables + ansible.builtin.include_vars: + file: web.yml + +- name: Create Web instance of mastodon + containers.podman.podman_container: + name: mastodon + image: ghcr.io/mastodon/mastodon:v4.5.5 + network: + - "{{ mastodon_networks['mastodon_internal']['name'] }}" + - "{{ mastodon_networks['mastodon_external']['name'] }}" + command: "bundle exec puma -C config/puma.rb" + env: + LOCAL_DOMAIN: "wtf.lt" + REDIS_HOST: redis + REDIS_PORT: 6379 + DB_HOST: database + DB_NAME: mastodon + DB_USER: "{{ mastodon_database.username }}" + DB_PASS: "{{ mastodon_database.password }}" + DB_PORT: 5432 + ES_ENABLED: true + ES_HOST: elasticsearch + ES_PORT: 9200 + ES_PRESET: single_node_cluster + ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: "{{ active_record_encryption.DETERMINISTIC_KEY }}" + ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: "{{ active_record_encryption.KEY_DERIVATION_SALT }}" + ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: "{{ active_record_encryption.PRIMARY_KEY }}" + VAPID_PRIVATE_KEY: "{{ vapid.PRIVATE_KEY }}" + VAPID_PUBLIC_KEY: "{{ vapid.PUBLIC_KEY }}" + SECRET_KEY_BASE: "{{ secret_key_base }}" + SMTP_SERVER: "{{ smtp.SERVER }}" + SMTP_PORT: "{{ smtp.PORT }}" + SMTP_LOGIN: "{{ smtp.LOGIN }}" + SMTP_PASSWORD: "{{ smtp.PASSWORD }}" + SMTP_FROM_ADDRESS: "{{ smtp.FROM_ADDRESS }}" + # inspect traefik container and add the IP address here + TRUSTED_PROXY_IP: "127.0.0.1/8,::1/128,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fc00::/7" + label: + traefik.enable: "true" + traefik.http.routers.mastodon.rule: "Host(`wtf.lt`)" + traefik.http.middlewares.mastodon-https-redirect.redirectscheme.scheme: "https" + traefik.http.routers.mastodon.middlewares: "mastodon-https-redirect" + traefik.http.routers.mastodon-secure.entrypoints: "https" + traefik.http.routers.mastodon-secure.rule: "Host(`wtf.lt`)" + traefik.http.routers.mastodon-secure.tls: "true" + traefik.http.routers.mastodon-secure.tls.certresolver: "lets-encrypt" + traefik.http.services.mastodon.loadbalancer.server.port: "3000" + volumes: + - "/home/apps/mastodon/system:/mastodon/public/system:z" + generate_systemd: + new: true + restart_policy: "always" + path: "~/.config/systemd/user/" + force: true + healthcheck: "curl -s --noproxy localhost localhost:3000/health | grep -q OK" + +- name: Activate mastodon web container service + ansible.builtin.systemd_service: + name: container-mastodon.service + state: started + enabled: true + scope: user diff --git a/roles/mastodon/vars/db.yml b/roles/mastodon/vars/db.yml new file mode 100644 index 0000000..056baad --- /dev/null +++ b/roles/mastodon/vars/db.yml @@ -0,0 +1,9 @@ +$ANSIBLE_VAULT;1.1;AES256 +32653863626339656666343361623163303264353236336331653335626662656632346639383638 +3534306263613061306464626534393239343230323766300a353565336131363939366364393232 +34326231333631613331636262376639656366343630653263356561633238303866636238623132 +3436323865343433610a313532336263353436333430653563613234623364346338633565373039 +34323737333136623663383063356533393438353631633538363739646636623363616166333333 +38393037306562643665623735313537323761323266613139393237343739353062633637323964 +31363364373934326338316238353632633339313032363939343561326463376461373838356136 +64326231303565623837 diff --git a/roles/mastodon/vars/main.yml b/roles/mastodon/vars/main.yml new file mode 100644 index 0000000..4a7e0ad --- /dev/null +++ b/roles/mastodon/vars/main.yml @@ -0,0 +1,19 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for mastodon + +mastodon_networks: + mastodon_internal: + name: mastodon_internal + driver: bridge + disable_dns: false + mastodon_external: + name: mastodon_external + driver: bridge + disable_dns: false + +mastodon_local_dirs: + - "~/mastodon/postgresql" + - "~/mastodon/redis" + - "~/mastodon/elasticsearch" + - "~/mastodon/system" diff --git a/roles/mastodon/vars/smtp.yml b/roles/mastodon/vars/smtp.yml new file mode 100644 index 0000000..dd4aeb1 --- /dev/null +++ b/roles/mastodon/vars/smtp.yml @@ -0,0 +1,12 @@ +$ANSIBLE_VAULT;1.1;AES256 +35666663373862393138616261633564306662353339643838356531653030633462653439613265 +6535666636663133313239386230303861613833383532360a373232316566646464306431653632 +39306338383138363635376361386435653334313936303335333263653861386533383230633563 +3037663336326364320a393763363763376434336361363835363537646661313032396561363462 +37336635373630336430316666306336383166626565376365356437353631323734333963353231 +62306430383332343666376361636638366430346431326439383836346362313363613235393334 +39373366633838356332653137383062323935376365356263313563626530316532623938643262 +38356165613734336436646162613163396133613030343131646337623235613764343965646330 +37623862306331316436323430306561393465633066333137366237316465396461353262653638 +65323336633131613965376162396361316238643639393739303065353833643666633132646630 +663664616362346266613837353564393934 diff --git a/roles/mastodon/vars/web.yml b/roles/mastodon/vars/web.yml new file mode 100644 index 0000000..77d2224 --- /dev/null +++ b/roles/mastodon/vars/web.yml @@ -0,0 +1,30 @@ +$ANSIBLE_VAULT;1.1;AES256 +36623335386437343631383832666131653063623931393164353030643037383034633234663739 +6630653465373839666333356435303236663262316630650a363466393765313931633564663937 +35303434633134393037363566326561376637666335333438376435333937316665626666633666 +3437393834646432320a653530613665393331363031646639353233613330323165303037333039 +33343162346132333733343730353735653437363438323030306366643133313964636130376537 +61373834343265353465646664626434643665306561376331623031643133643164643233626264 +64396531646636613030633130336537373534633137666262623134613138306438363030616432 +32306564633762633333383739353061313134386565353264663866316334666663343832323034 +64343432363631643731633030613166383136306638373634343431356437326462323431613530 +39336130333435373334666638616137326262343565313865333961646238613935306531616332 +38393939356461636536316331356137353362613330616231623237393637393163343131313036 +66333966383538386430623234356466663564393739393261396664666666386131633030623737 +37323364656561393931643132306265393137303938663833613135366561373835643264363161 +36396337616430363764356436363632306235623732623633373337613764663665313862633632 +62616637653233666437326230326532346165343062326631646534396162346439616666373763 +39633833376238376435333730613539626237306536303661373164386133353238353733343866 +61383163333538303361376332356538323135376161316363393639633464356333666134313063 +61336264653661633839396536623864626339303330383433626136316630373464313136666338 +63396362623766383131353935616562353261343336303233363465656535333035616638373539 +61343133623232613139333537623532333063356163363963653064666264323162323437623839 +33383064653436366338393030613862616638623434376530373132646165316433316439343636 +37383437353734316235313931313432326630626362363238636333323662393739303830613463 +39393038666339386435313164333731386364316261313932336230346365663236653135653964 +37626536373661303834633561353631643265646234346136326563316161323334386631303966 +66613830316539393062656138353637656462336462623733386165353934636465373535393837 +64373761383832643033353161306339343533326531343332373063343531393432633566663035 +38373666343064316435333636333838373539316666386635643233343038333031396261623339 +39346665373831353730366532306661343630356666303862626364356439306666346466306130 +35653539626132386166386531643366646564633031346264333065333462383063 diff --git a/roles/podman/README.md b/roles/podman/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/podman/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/podman/defaults/main.yml b/roles/podman/defaults/main.yml new file mode 100644 index 0000000..1fe5fcc --- /dev/null +++ b/roles/podman/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for podman diff --git a/roles/podman/handlers/main.yml b/roles/podman/handlers/main.yml new file mode 100644 index 0000000..2d7ba3f --- /dev/null +++ b/roles/podman/handlers/main.yml @@ -0,0 +1,7 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for podman + +- name: Podman migrate + ansible.builtin.command: + cmd: podman system migrate diff --git a/roles/podman/meta/main.yml b/roles/podman/meta/main.yml new file mode 100644 index 0000000..10ad31b --- /dev/null +++ b/roles/podman/meta/main.yml @@ -0,0 +1,36 @@ +--- +# SPDX-License-Identifier: MIT-0 +galaxy_info: + author: Simonas K. + description: podman for mastodon + company: wtf.lt + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/podman/tasks/main.yml b/roles/podman/tasks/main.yml new file mode 100644 index 0000000..3c55bc4 --- /dev/null +++ b/roles/podman/tasks/main.yml @@ -0,0 +1,76 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for podman + +- name: Install deps + ansible.builtin.dnf: + name: "{{ dnf_packages }}" + +- name: Enable firewalld + ansible.builtin.systemd: + name: firewalld + enabled: true + state: started + +- name: Add ports + ansible.posix.firewalld: + service: "{{ item }}" + state: enabled + permanent: true + immediate: true + loop: "{{ firewalld_services }}" + +- name: Create unprivileged user {{ podman_user }} + ansible.builtin.user: + name: "{{ podman_user }}" + uid: "{{ podman_uid }}" + create_home: true + +- name: Set subuid / subgid range for {{ podman_user }} + ansible.builtin.lineinfile: + path: "{{ item }}" + line: "apps:1000000:65537" + loop: + - "/etc/subuid" + - "/etc/subgid" + notify: + - podman migrate + +- name: Check linger + ansible.builtin.command: + cmd: "loginctl show-user {{ podman_user }}" + changed_when: false + register: linger_check + +- name: Enable linger + ansible.builtin.command: + cmd: "loginctl enable-linger {{ podman_uid }}" + creates: "/var/lib/systemd/linger/{{ podman_user }}" + +- name: Persist unprivileged port + ansible.posix.sysctl: + sysctl_file: /etc/sysctl.d/user_priv_ports.conf + name: net.ipv4.ip_unprivileged_port_start + value: "53" + sysctl_set: true + reload: true + +- name: Install python package + ansible.builtin.command: + cmd: pip3 install podman-compose + creates: /usr/local/bin/podman-compose + +- name: Remove memlock limit in pam_limits for {{ podman_user }} + community.general.pam_limits: + domain: "{{ podman_user }}" + limit_type: "-" + limit_item: memlock + value: unlimited + comment: unlimited memory lock for elasticsearch + +- name: Ramp up nofile lmit for {{ podman_user }} + community.general.pam_limits: + domain: "{{ podman_user }}" + limit_type: "-" + limit_item: nofile + value: 65536 diff --git a/roles/podman/vars/main.yml b/roles/podman/vars/main.yml new file mode 100644 index 0000000..2aebb5d --- /dev/null +++ b/roles/podman/vars/main.yml @@ -0,0 +1,19 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for podman + +dnf_packages: + - podman + - python3-pip + - firewalld + - bash-completion + - dnf-automatic + +firewalld_services: + - http + - https + +podman_user: apps +podman_uid: 1000 + +min_user_port: 53 diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..e926744 --- /dev/null +++ b/site.yml @@ -0,0 +1,14 @@ +--- +- name: Setup podman + hosts: all + remote_user: root + gather_facts: false + roles: + - podman + +- name: Setup mastodon with LB + hosts: all + gather_facts: false + roles: + - infra + - mastodon