Lemmy setup with Ansible, Podman and external Nginx
Hello, I thought I'd share my own setup with Ansible.Two motivations that played a factor here. First, I wanted to use Podman instead of Docker and second, I already have an Nginx Proxy that I wanted to use it. Lastly, I like managing my containers through systemd, which is very easy to do with Podman.Tested on Debian 11, though it should work on most other distros as well.Do look over the playbook, there might be some decisions you don't agree with. For example, the different directories I'm creating for the various containers. (I'm creating multiple directories under /mnt)Other variables, mainly logins, are already modifyable using the Ansible vault file included here.
Requirements
A Server
SSH access to the server
Ansible Inventory file
Basic knowledge of Ansible
Basic knowledge of Nginx
SMTP server EDIT 2023-06-15
Setup
Vault file
I'll start with the vault file. Enter your values between the quotes. Explainations for most of them can be found in the lemmy.hjson config file.
Encrypt your file with this command.$ ansible-vault encrypt vault.ymlYou can also view or edit the file by replacing the encrypt keyword with view or edit respectively.
Lemmy config
Here's the lemmy config I used. It is mostly copied from the default config example, though a lot of the values have been replaced by the variables you just filled in above.(btw, federation still does work with tls_enabled: true commented like this. As proof, I'm writing this post from my own instance set up this way)
{
# settings related to the postgresql database
database: {
# Username to connect to postgres
user: "{{ var_postgres_user }}"
# Password to connect to postgres
password: "{{ var_postgres_password }}"
# Host where postgres is running
host: "lemmy-db"
# Port where postgres can be accessed
port: 5432
# Name of the postgres database for lemmy
database: "lemmy"
# Maximum number of active sql connections
pool_size: 5
}
# Settings related to activitypub federation
# Pictrs image server configuration.
pictrs: {
# Address where pictrs is available (for image hosting)
url: "http://lemmy-pictrs:8080/"
# Set a custom pictrs API key. ( Required for deleting images )
api_key: "{{ var_pictrs_api_key }}"
}
# Email sending configuration. All options except login/password are mandatory
email: {
# Hostname and port of the smtp server
smtp_server: "{{ var_smtp_server }}"
# Login name for smtp server
smtp_login: "{{ var_smtp_login }}"
# Password to login to the smtp server
smtp_password: "{{ var_smtp_password }}"
# Address to send emails from, eg "[email protected]"
smtp_from_address: "{{ var_smtp_from }}"
# Whether or not smtp connections should use tls. Can be none, tls, or starttls
tls_type: "{{ var_smtp_tls }}"
}
# Parameters for automatic configuration of new instance (only used at first start)
setup: {
# Username for the admin user
admin_username: "{{ var_admin_username }}"
# Password for the admin user. It must be at least 10 characters.
admin_password: "{{ var_admin_password }}"
# Name of the site (can be changed later)
site_name: "{{ var_site_name }}"
# Email for the admin user (optional, can be omitted and set later through the website)
admin_email: "{{ var_admin_email }}"
}
# the domain name of your instance (mandatory)
hostname: "{{ var_hostname }}"
# Address where lemmy should listen for incoming requests
bind: "0.0.0.0"
# Port where lemmy should listen for incoming requests
port: 8536
# Whether the site is available over TLS. Needs to be true for federation to work.
#tls_enabled: true
}
Ansible Playbook
Now a quick overview of my playbook:
Installs podman
The systemd service for running the podman pod will be stopped. EDIT: The error will now be caught and continue
Run the playbook with this command.$ ansible-playbook -i inventory.yml -e @vault.yml --ask-vault-pass playbook.yml -KYou will be prompted for the sudo password and the password you set for your encrypted vault.If you authenticate to ssh using a password, add -k to the above command and you'll be prompted for that as well.
There's a character limit on posts, so I'll put the rest as a comment below.