Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
506cd00
Performance fixes for postgres
snowe2010 Jun 21, 2023
8e3a355
Merge branch 'main' into programming.dev/psql-perf-updates
snowe2010 Jun 23, 2023
27af5bf
Merge remote-tracking branch 'upstream/main' into programming.dev/psq…
snowe2010 Jul 7, 2023
ef518f5
Merge remote-tracking branch 'upstream/main' into programming.dev/psq…
snowe2010 Jul 29, 2023
351c2ab
Merge branch 'main' into programming.dev/psql-perf-updates
snowe2010 Jul 29, 2023
f45f204
configure debian docker apt repos (#140)
eslerm Aug 2, 2023
a95c332
Updating VERSION
dessalines Aug 8, 2023
1dc5cfb
Merge remote-tracking branch 'upstream/main' into programming.dev/psq…
snowe2010 Aug 10, 2023
b9787ae
Fix duplicate headers being sent
codyro Aug 11, 2023
3b7ff00
Fix pictrs environent variable for setting API_KEY (#153)
usr3 Aug 30, 2023
627432b
Get dpkg-formatted arch and use it for docker apt repo (#148)
codyro Aug 30, 2023
53f0930
Remove redundant gzip lines
codyro Aug 31, 2023
1a68715
Initial commit of pict-rs external configuration
codyro Sep 1, 2023
829fec3
Update README
codyro Sep 1, 2023
276eb3e
- Loop over variables and populate docker-compose.yml
codyro Sep 1, 2023
b9fd747
Fix duplicate headers being sent by nginx (#151)
codyro Sep 1, 2023
c14098e
Remove reliance on `pip` module (#157)
codyro Sep 2, 2023
b260182
Lemmy AlmaLinux/RHEL Ansible Support (#145)
codyro Sep 2, 2023
a4af565
Also test for python3 installation (#156)
sanatsathaye Sep 2, 2023
4401e15
Add `PICTRS__SERVER__API_KEY` to pict-rs configuration example
codyro Sep 2, 2023
4b8a5c4
Merge branch 'main' into pictrs-configuration
codyro Sep 2, 2023
a8c859d
Move all pict-rs environmentals to external variables file
codyro Sep 2, 2023
31631d2
Adjust inventory example to use `ansible_user`
codyro Sep 2, 2023
6b671f1
Quote variable in examples/vars.yml
codyro Sep 2, 2023
3909b5e
Adjust README.md to reflect `vars.yml` file
codyro Sep 2, 2023
2c9b9aa
Fix incorrect/inconsistent usage of `proxy_set_header` in nginx_inter…
codyro Sep 2, 2023
fb65a14
Adjust paths to be consistent with documentation (#162)
codyro Sep 4, 2023
62972fe
Adding CODEOWNERS (#158)
dessalines Sep 4, 2023
459d24f
Adding ticoombs to codeowners. (#163)
dessalines Sep 4, 2023
ed7089c
Remove legacy headers as per @Nutomic
codyro Sep 4, 2023
03a2817
Clean up unnecessary whitespace control in Jinja2 tags
codyro Sep 4, 2023
07d997e
Merge pull request #161 from codyro/nginx-internal-proxy-fix-gh155
codyro Sep 4, 2023
78af02b
Fix nginx connect 111 error. (#165)
dessalines Sep 10, 2023
1fa49a2
Fix inventory path
codyro Sep 10, 2023
701cb50
Move other env vars to vars.yml
codyro Sep 11, 2023
b655c61
Merge branch 'main' into pictrs-configuration
codyro Sep 11, 2023
aae213e
Merge pull request #160 from codyro/pictrs-configuration
codyro Sep 11, 2023
70eec4c
Fix ansible-lint warnings
Nothing4You Sep 10, 2023
5be6b18
Merge pull request #166 from Nothing4You/ansible-lint
codyro Sep 11, 2023
8503e65
Fix change that broke notify/reload, update nginx handler (#167)
codyro Sep 12, 2023
6aaf939
Fix path to docker-daemon.json
sanatsathaye Sep 13, 2023
9c81d79
Merge pull request #168 from sanatsathaye/main
codyro Sep 13, 2023
0852352
Update `Upgrading` section, add basic sanity checks for old files and…
codyro Sep 14, 2023
f5bc407
Missing a word
codyro Sep 14, 2023
3555ae2
Explicitly import `inventory/host_vars/{{ domain }}/vars.yml`
codyro Sep 14, 2023
550cf82
Run `prettier` on `README.md`
codyro Sep 14, 2023
bbe8bc6
Remove sneaky `"`
codyro Sep 15, 2023
215d714
Merge pull request #172 from codyro/docs-upgrading
codyro Sep 16, 2023
0c23f4d
feat: pictrs-safety
db0 Sep 23, 2023
a2bd86b
doc: wrong var
db0 Sep 23, 2023
98d9742
fix: versioned the container
db0 Sep 24, 2023
b6e703f
ref: adjusted as per comments
db0 Sep 27, 2023
963ab7b
Add vars.yml to woodpecker pipeline (#176)
codyro Sep 27, 2023
c203471
Updating VERSION
dessalines Sep 29, 2023
bccdc4e
Merge branch 'main' of https://github.com/LemmyNet/lemmy-ansible
dessalines Sep 29, 2023
6d610c9
Update ansible.cfg (#178)
ticoombs Oct 4, 2023
d7be6c3
Make firewalld operations idempotent (#173)
sanatsathaye Oct 4, 2023
3b451d8
feat: Version 1.2.0 documentation (#179)
ticoombs Oct 4, 2023
b5c2e92
Merge pull request #175 from db0/pictrs-safety
codyro Oct 5, 2023
ad719a8
Merge remote-tracking branch 'upstream/main' into programming.dev/psq…
snowe2010 Oct 8, 2023
84e904c
Updating the lemmy_env_vars after upgrade
snowe2010 Oct 8, 2023
a9139e2
fix: noqa on linelength for password imports
ticoombs Oct 9, 2023
c130322
Merge pull request #186 from LemmyNet/ticoombs-patch-4
codyro Oct 9, 2023
31f1137
fix: force no become on localhost (#185)
ticoombs Oct 9, 2023
22aa431
config fix for postgres docker defaults (#183)
Fmstrat Oct 9, 2023
5c68d95
Adjust permissions for the distribute /etc/postgresql.conf so `postgr…
codyro Oct 9, 2023
7f1a879
Merge pull request #187 from codyro/postgres-config-permissions
ticoombs Oct 9, 2023
300a261
Update ansible requirements, remove `become` for localhost delegated …
codyro Oct 13, 2023
9676c75
Remove invalid `temp_file_size` line in `customPostgresql.conf` (#192)
codyro Oct 17, 2023
a3b210f
Adding /version route
dessalines Oct 18, 2023
5114615
Merge pull request #193 from LemmyNet/add_version_route
codyro Oct 18, 2023
0af5869
Redirecting version to nodeinfo.
dessalines Oct 20, 2023
e059c2e
Merge pull request #194 from LemmyNet/add_version_route_2
codyro Oct 20, 2023
ebad432
Revert "Redirecting version to nodeinfo."
dessalines Oct 23, 2023
fdb8c18
Merge pull request #196 from LemmyNet/revert-194-add_version_route_2
codyro Oct 23, 2023
51a82f7
chore: 1.2.1 update docs (#198)
ticoombs Oct 25, 2023
a292378
Redirect "/sitemap.xml" to backend
ismailkarsli Nov 9, 2023
0153dc1
Merge pull request #199 from ismailkarsli/main
codyro Nov 9, 2023
196761c
Include CPU architectures in requirements
Nutomic Nov 29, 2023
63adf2e
Update README.md
Nutomic Nov 29, 2023
8612dba
Update README.md
Nutomic Nov 29, 2023
144b414
Merge pull request #201 from LemmyNet/Nutomic-patch-3
codyro Nov 29, 2023
e6f2198
Update to pictrs and fix for debian
snowe2010 Nov 30, 2023
0232df1
Fix alma playbook running on non-alma system
sanatsathaye Dec 3, 2023
1178eed
Fix debian playbook running on non-debian system
sanatsathaye Dec 3, 2023
d00ab06
Merge pull request #202 from sanatsathaye/main
codyro Dec 4, 2023
d223633
Updating VERSION
dessalines Dec 15, 2023
6ecaeaa
Adding a 1GB shm size for postgres, to prevent shared space error. (#…
dessalines Dec 16, 2023
82fefee
Version 1.3.0 (#206)
ticoombs Dec 18, 2023
aecc0e2
fix: nginx real-ips in logs & docker constant resolution for scaling …
ticoombs Dec 18, 2023
68d68d0
Updating VERSION
dessalines Dec 20, 2023
c553dcb
Merge remote-tracking branch 'upstream/main' into programming.dev/psq…
snowe2010 Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Nutomic @dessalines @codyro @ticoombs
8 changes: 7 additions & 1 deletion .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ pipeline:
prettier_markdown_check:
image: tmknom/prettier
commands:
- prettier -c "*.md" "*.yml"
- prettier -c "*.md" "*.yml" "examples/vars.yml"
check_ansible_format:
image: alpine:3
commands:
- apk add ansible
- ansible-playbook lemmy.yml --syntax-check
- ansible-playbook lemmy-almalinux.yml --syntax-check
- ansible-playbook uninstall.yml --syntax-check
ansible_lint:
image: alpine:3
commands:
- apk add ansible ansible-lint
- ansible-lint --warn-list experimental lemmy.yml lemmy-almalinux.yml uninstall.yml examples/vars.yml
115 changes: 107 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
# Lemmy-Ansible

This provides an easy way to install [Lemmy](https://github.com/LemmyNet/lemmy) on any server. It automatically sets up an nginx server, letsencrypt certificates, and email.
This provides an easy way to install [Lemmy](https://github.com/LemmyNet/lemmy) on any server. It automatically sets up an nginx server, letsencrypt certificates, docker containers, pict-rs, and email smtp.

## Requirements

To run this ansible playbook, you need to:

- Have a Debian-based server / VPS where lemmy will run.
- Have a Debian/AlmaLinux 9-based server / VPS where lemmy will run.
- Supported CPU architectures are x86-64 and ARM64.
- Configure a DNS `A` Record to point at your server's IP address.
- Make sure you can ssh to it, with a sudo user: `ssh <your-user>@<your-domain>`
- Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on your **local** machine (do not install it on your destination server).
- Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) (>= `2.11.0` on your **local** machine (do not install it on your destination server).

### Supported Distribution Playbook Matrix

These are the distributions we currently support. Anything not listed here is currently not supported.
If you wish to see another distribution on the list, please test on the latest commit in `main` and report your findings via an Issue.

| Distribution | Version | Playbook |
| ------------ | --------- | --------------------- |
| Debian | 10 | `lemmy.yml` |
| Debian | 11 | `lemmy.yml` |
| Debian | 12 | `lemmy.yml` |
| Ubuntu | 22.04 LTS | `lemmy.yml` |
| RHEL | 9 | `lemmy-almalinux.yml` |

## Install

1. Clone this repo:
1. Clone this repo & checkout latest tag

```
git clone https://github.com/LemmyNet/lemmy-ansible.git
cd lemmy-ansible
git checkout $(git describe --tags)
```

2. Make a directory to hold your config:
Expand All @@ -44,7 +59,15 @@ To run this ansible playbook, you need to:

You can use [the PGTune tool](https://pgtune.leopard.in.ua) to tune your postgres to meet your server memory and CPU.

6. Run the playbook:
6. Copy the sample `vars.yml` file

`cp examples/vars.yml inventory/host_vars/<your-domain>/vars.yml`

Edit the `inventory/host_vars/<your-domain>/vars.yml` file to your liking.

7. Run the playbook:

_Note_: See the "Supported Distribution Playbook Matrix" section above if you should use `lemmy.yml` or not

`ansible-playbook -i inventory/hosts lemmy.yml`

Expand All @@ -66,9 +89,85 @@ To run this ansible playbook, you need to:

## Upgrading

- Run `git pull`
- Check out the [Lemmy Releases Changelog](https://github.com/LemmyNet/lemmy/blob/main/RELEASES.md) to see if there are any config changes with the releases since your last.
- Run `ansible-playbook -i inventory/hosts lemmy.yml --become`
Since version `1.1.0` we no longer default to using `main` but use tags to make sure deployments are versioned.
With every new release all migration steps shall be written below so make sure you check out the [Lemmy Releases Changelog](https://github.com/LemmyNet/lemmy/blob/main/RELEASES.md) to see if there are any config changes with the releases since your last read.

### Upgrading to 1.3.0 (Lemmy 0.19.0 & pictrs-0.4.7)

This is a major change and has required reading! tl;dr

- Lemmy has been upgraded to 0.19.0
- pict-rs has been upgraded to 0.4.7
- pict-rs has not been integrated with postgres yet
- "Optional Modules" are now available to be added to your lemmy install as provided by the community.
- The first being pictrs-safety

#### Steps

- Prepare to have downtime as the database needs to perform migrations!
- Run `git pull && git checkout 1.3.0`
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`
- Lemmy will now be down! In testing this takes from 20 to 60 minutes.
- If you are bored you can ssh into your server, and check the logs on postgres for updates
- `docker compose logs -f postgres` while ssh'd and in your Lemmy directory

#### Update your pict-rs sled-database (Optional)

If you are happy for pict-rs to be down _for a while_ go straight to our `1.3.1` git tag which updates pictrs to 0.5.0. Otherwise keep reading.
Starting with 0.5.0 your database will automatically upgrade to the latest version, which will cause downtime for your users.
As such there is an intermediary step where you can upgrade your database in the background to prepare for 0.5 (Reference documentation)[https://git.asonix.dog/asonix/pict-rs/releases#user-content-upgrade-preparation-endpoint]. This ensure no-one is caught out by unforseen downtime of multiple services.

Once you have deployed lemmy-ansible `1.3.0` tag, please continue (if you want):

- Take note of what your pict-rs API Key is under `vars.yml`
- Take note of what your docker network name is. (It's normally the domain without any extra characters)
- You should be able to find it via: `docker network ls | grep _default` if in doubt.
- Run the following command replacing `api-key` with the pict-rs api key, & `youdomain` with the network name.
- `docker run --network yourdomain_default --rm curlimages/curl:8.5.0 --silent -XPOST -H'X-Api-Token: api-key' 'http://pictrs:8080/internal/prepare_upgrade'`
- This will start the background process updating your database from 0.4 to 0.5 compatible.

This is only Optional, and takes a shorter amount of time than the Lemmy database upgrade, but on huge installations it may take a lot longer.

#### Optional Module(s)

Our first optional module is [pictrs-safety](https://github.com/db0/pictrs-safety). See the repo linked for more information, especially for integration with pictrs (which is what it is for) Thanks to @db0 for their contribution.
See the `pictrs_safety_env_vars` under `examples/vars.yml` for relevant options (and the two password variables)
To enable this module to be used you must ADD `pictrs_safety: true` to your `vars.yml`.

### Upgrading to 1.2.1 (Lemmy 0.18.5)

This is a minor change which fixes the issue with the Postgres container not using the `customPostgres.conf` file.

#### Steps

- Please regenerate your `customPostgres.conf` from `examples/customPostgres.conf`
- **OR**
- Add the following block to your current customPostgres file.

```
# Listen beyond localhost
listen_addresses = '*'
```

### Upgrading to 1.2.0 (Lemmy 0.18.5)

Major changes:

- All variables are not under a singular file so you will not need to modify anything: `inventory/host_vars/{{ domain }}/vars.yml`
- `--become` is now optional instead of forced on

#### Steps

- Run `git pull && git checkout 1.2.0`
- When upgrading from older versions of these playbooks, you will need to do the following:
- Rename `inventory/host_vars/{{ domain }}/passwords/postgres` file to `inventory/host_vars/{{ domain }}/passwords/postgres.psk`
- Copy the `examples/vars.yml` file to `inventory/host_vars/{{ domain }}/vars.yml`
- Edit your variables as desired
- Run your regular deployment. Example: `ansible-playbook -i inventory/hosts lemmy.yml --become`

### Upgrading to 1.1.0 (Lemmy 0.18.3)

- No major changes should be required

## Migrating your existing install to use this deploy

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.18.3
0.19.1
3 changes: 0 additions & 3 deletions ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ inventory = inventory

[ssh_connection]
pipelining = True

[privilege_escalation]
become = True
4 changes: 3 additions & 1 deletion examples/customPostgresql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ max_parallel_workers = 4
max_parallel_maintenance_workers = 2

# Other custom params
temp_file_size=1GB
synchronous_commit=off
# This one shouldn't be on regularly, because DB migrations often take a long time
# statement_timeout = 10000

# Listen beyond localhost
listen_addresses = '*'
4 changes: 3 additions & 1 deletion examples/hosts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[lemmy]
# to get started, copy this file to `inventory` and adjust the values below.
# - `myuser@example.com`: replace with the destination you use to connect to your server via ssh
# - `ansible_user=root`: replace `root` with your the username you use to connect to your ssh server
# - `domain=example.com`: replace `example.com` with your lemmy domain
# - `letsencrypt_contact_email=your@email.com` replace `your@email.com` with your email address,
# to get notifications if your ssl cert expires
# - `lemmy_base_dir=/srv/lemmy`: the location on the server where lemmy can be installed, can be any folder
# if you are upgrading from a previous version, set this to `/lemmy`
# - `lemmy_version`: <Optional> The back end version.
# - `lemmy_ui_version`: <Optional> overrides the front end version.
myuser@example.com domain=example.com letsencrypt_contact_email=your@email.com lemmy_base_dir=/srv/lemmy
# - `pictrs_safety`: <Optional> If true, a docker container for pictrs-safety will be deployed and pict-rs will be configured to validate images through it. You will also need to set up a fedi-safety worker to validate the images.
example.com ansible_user=root domain=example.com letsencrypt_contact_email=your@email.com lemmy_base_dir=/srv/lemmy pictrs_safety=false

[all:vars]
ansible_connection=ssh
51 changes: 51 additions & 0 deletions examples/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
postgres_password: "{{ lookup('password', 'inventory/host_vars/{{ domain }}/passwords/postgres.psk chars=ascii_letters,digits') }}" # noqa yaml[line-length]:w

# Next two only relevant if pictrs_safety == True
pictrs_safety_worker_auth: "{{ lookup('password', 'inventory/host_vars/{{ domain }}/passwords/pictrs_safety_worker_auth.psk chars=ascii_letters,digits length=15') }}" # noqa yaml[line-length]
pictrs_safety_secret: "{{ lookup('password', 'inventory/host_vars/{{ domain }}/passwords/pictrs_safety_secret.psk chars=ascii_letters,digits length=80') }}" # noqa yaml[line-length]

# You can set any pict-rs environmental variables here. They will populate the templates/docker-compose.yml file.
# https://git.asonix.dog/asonix/pict-rs
pictrs_env_vars:
- PICTRS__SERVER__API_KEY: "{{ postgres_password }}"
- PICTRS__MEDIA__VIDEO_CODEC: vp9
- PICTRS__MEDIA__GIF__MAX_WIDTH: 256
- PICTRS__MEDIA__GIF__MAX_HEIGHT: 256
- PICTRS__MEDIA__GIF__MAX_AREA: 65536
- PICTRS__MEDIA__GIF__MAX_FRAME_COUNT: 400
- PICTRS_OPENTELEMETRY_URL: http://otel:4137
- RUST_LOG: debug
- RUST_BACKTRACE: full
# - PICTRS__STORE__TYPE: object_storage
# - PICTRS__STORE__ENDPOINT: '<S3 endpoint>'
# - PICTRS__STORE__BUCKET_NAME: '<bucket name>'
# - PICTRS__STORE__REGION: '<region>'
# - PICTRS__STORE__USE_PATH_STYLE: false
# - PICTRS__STORE__ACCESS_KEY: '<access key>'
# - PICTRS__STORE__SECRET_KEY: '<secret key>'

postgres_env_vars:
- POSTGRES_USER: lemmy
- POSTGRES_PASSWORD: "{{ postgres_password }}"
- POSTGRES_DB: lemmy

lemmy_env_vars:
- RUST_LOG: warn
- MAX_DB_CONNECTIONS=20

lemmyui_env_vars:
- LEMMY_UI_LEMMY_INTERNAL_HOST: lemmy:8536
- LEMMY_UI_LEMMY_EXTERNAL_HOST: "{{ domain }}"
- LEMMY_UI_HTTPS: true

postfix_env_vars:
- POSTFIX_myhostname: "{{ domain }}"

pictrs_safety_env_vars:
# Use this in your fedi-safety to allow your worker to authenticate to pictrs-safety
- FEDIVERSE_SAFETY_WORKER_AUTH: "{{ pictrs_safety_worker_auth }}"
- FEDIVERSE_SAFETY_IMGDIR: "/tmp/images"
- USE_SQLITE: 1
- secret_key: "{{ pictrs_safety_secret }}"
- SCAN_BYPASS_THRESHOLD: 10
- MISSING_WORKER_THRESHOLD: 5
4 changes: 4 additions & 0 deletions files/proxy_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Loading