From df2db64e9ae9428bfa9044785f6adfc02e0363e3 Mon Sep 17 00:00:00 2001 From: fadelkon Date: Mon, 28 Mar 2022 20:39:35 +0200 Subject: [PATCH] Render nginx templates into sites-available (#30) Render nginx templates into sites-available and then symlink them. Instead of rendering them directly to sites-enabled. It's a good practice and makes it easier for disabling or substituting temporarily a site config. Currently, the sites-enabled file is a regular file. If we just try to replace it with a symlink, it fails. To avoid upgrade conflicts, i add 2 tasks to remove the file if it's regular instead of a symlink. We could just delete it always before symlinking, but then we would generate unnecessary activity and "changed" noise in the output. Tested with a running instance. --- lemmy.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lemmy.yml b/lemmy.yml index 3b6dcae..c188442 100644 --- a/lemmy.yml +++ b/lemmy.yml @@ -65,12 +65,30 @@ dest: '{{lemmy_base_dir}}/{{domain}}/docker-compose.yml' mode: '0600' - src: 'templates/nginx.conf' - dest: '/etc/nginx/sites-enabled/{{domain}}.conf' + dest: '/etc/nginx/sites-available/{{domain}}.conf' mode: '0644' vars: lemmy_docker_image: "dessalines/lemmy:{{ lemmy_version | default( lookup('file', 'VERSION') )}}" lemmy_docker_ui_image: "dessalines/lemmy-ui:{{ lemmy_ui_version | default(lemmy_version | default(lookup('file', 'VERSION')))}}" + - block: + - name: gather stats on site enabled config + stat: + path: "/etc/nginx/sites-enabled/{{domain}}.conf" + register: reg_enabled + + - name: remove if regular file (legacy) instead of symlink + file: + path: "/etc/nginx/sites-enabled/{{domain}}.conf" + state: absent + when: reg_enabled.stat.isreg + + - name: enable nginx site + file: + src: '../sites-available/{{domain}}.conf' + dest: "/etc/nginx/sites-enabled/{{domain}}.conf" + state: link + - name: add the config.hjson template: src: 'inventory/host_vars/{{domain}}/config.hjson'