liab-deployments/liab_deployments/operations/caddy.py

37 lines
758 B
Python

from pyinfra import host
from pyinfra.operations import (
files,
systemd,
)
def caddyfile_block(
*,
marker,
content,
reload=True,
**kwargs,
):
"""Put a block into the caddyfile and reload, if desired and needed
"""
_block = files.block(
name=f'Caddy block {marker}',
path=host.data.get('caddyfile_path', '/etc/caddy/Caddyfile'),
marker=f'# {{mark}} {marker}',
content=content,
present=True,
try_prevent_shell_expansion=True,
**kwargs,
)
if not reload:
return
systemd.service(
name='Reload caddy',
service='caddy.service',
running=True,
reloaded=True,
_if=_block.did_change,
**kwargs,
)