From 9f9bcc48a85bd7f0d6a76d196777a280b4a78435 Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 7 Jul 2023 09:28:37 +0200 Subject: [PATCH] avoid UnboundLocalError for config_link.changed if enabled is False --- pyinfra_nginx/nginx.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyinfra_nginx/nginx.py b/pyinfra_nginx/nginx.py index 1577c3c..1a18403 100644 --- a/pyinfra_nginx/nginx.py +++ b/pyinfra_nginx/nginx.py @@ -13,6 +13,8 @@ def _install_nginx(): if not host.get_fact(DebPackages): raise DeployError(("Can't deploy prerequisites on non-deb system")) + apt.update(cache_time=3600 * 24) + apt.packages( name = "Install nginx-extras", packages = ["nginx-extras"], @@ -33,15 +35,14 @@ def add_nginx_domain(domain: str, config_path: str, enabled=True): deploy_acmetool(nginx_hook=True, domains=[domain]) - config = files.put( - src=config_path, - dest=f"/etc/nginx/sites-available/{domain}", - user="root", - group="root", - mode="644", - ) - if enabled: + config = files.put( + src=config_path, + dest=f"/etc/nginx/sites-available/{domain}", + user="root", + group="root", + mode="644", + ) config_link = files.link( path=f"/etc/nginx/sites-enabled/{domain}", target=f"/etc/nginx/sites-available/{domain}", @@ -49,9 +50,8 @@ def add_nginx_domain(domain: str, config_path: str, enabled=True): group="root", present=enabled, ) - - if config.changed or config_link.changed: - need_restart = True + if config.changed or config_link.changed: + need_restart = True systemd.service( name="NGINX should be enabled and running",