avoid UnboundLocalError for config_link.changed if enabled is False

This commit is contained in:
missytake 2023-07-07 09:28:37 +02:00
parent 0f3271a1e9
commit 9f9bcc48a8

View file

@ -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",