Attempt to generate Jinja2 templates of systemd unit files and Postfix main.cf (now that JinjaTurtle supports it)
This commit is contained in:
parent
e0ef5ede98
commit
8daed96b7c
3 changed files with 55 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# 0.4.0 (not yet released)
|
# 0.4.0 (not yet released)
|
||||||
|
|
||||||
* Introduce `enroll validate` - a tool to validate a harvest against the state schema, or check for missing or orphaned obsolete artifacts in a harvest.
|
* Introduce `enroll validate` - a tool to validate a harvest against the state schema, or check for missing or orphaned obsolete artifacts in a harvest.
|
||||||
|
* Attempt to generate Jinja2 templates of systemd unit files and Postfix main.cf (now that JinjaTurtle supports it)
|
||||||
|
|
||||||
# 0.3.0
|
# 0.3.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,45 @@ from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
SUPPORTED_EXTS = {".ini", ".json", ".toml", ".yaml", ".yml", ".xml"}
|
SYSTEMD_SUFFIXES = {
|
||||||
|
".service",
|
||||||
|
".socket",
|
||||||
|
".target",
|
||||||
|
".timer",
|
||||||
|
".path",
|
||||||
|
".mount",
|
||||||
|
".automount",
|
||||||
|
".slice",
|
||||||
|
".swap",
|
||||||
|
".scope",
|
||||||
|
".link",
|
||||||
|
".netdev",
|
||||||
|
".network",
|
||||||
|
}
|
||||||
|
|
||||||
|
SUPPORTED_SUFFIXES = {
|
||||||
|
".ini",
|
||||||
|
".cfg",
|
||||||
|
".json",
|
||||||
|
".toml",
|
||||||
|
".yaml",
|
||||||
|
".yml",
|
||||||
|
".xml",
|
||||||
|
".repo",
|
||||||
|
} | SYSTEMD_SUFFIXES
|
||||||
|
|
||||||
|
|
||||||
|
def infer_other_formats(dest_path: str) -> Optional[str]:
|
||||||
|
p = Path(dest_path)
|
||||||
|
name = p.name.lower()
|
||||||
|
suffix = p.suffix.lower()
|
||||||
|
# postfix
|
||||||
|
if name == "main.cf":
|
||||||
|
return "postfix"
|
||||||
|
# systemd units
|
||||||
|
if suffix in SYSTEMD_SUFFIXES:
|
||||||
|
return "systemd"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
|
@ -22,9 +60,15 @@ def find_jinjaturtle_cmd() -> Optional[str]:
|
||||||
return shutil.which("jinjaturtle")
|
return shutil.which("jinjaturtle")
|
||||||
|
|
||||||
|
|
||||||
def can_jinjify_path(path: str) -> bool:
|
def can_jinjify_path(dest_path: str) -> bool:
|
||||||
p = Path(path)
|
p = Path(dest_path)
|
||||||
return p.suffix.lower() in SUPPORTED_EXTS
|
suffix = p.suffix.lower()
|
||||||
|
if infer_other_formats(dest_path):
|
||||||
|
return True
|
||||||
|
# allow unambiguous structured formats
|
||||||
|
if suffix in SUPPORTED_SUFFIXES:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def run_jinjaturtle(
|
def run_jinjaturtle(
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Set, Tuple
|
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
from .jinjaturtle import (
|
from .jinjaturtle import (
|
||||||
find_jinjaturtle_cmd,
|
|
||||||
can_jinjify_path,
|
can_jinjify_path,
|
||||||
|
find_jinjaturtle_cmd,
|
||||||
|
infer_other_formats,
|
||||||
run_jinjaturtle,
|
run_jinjaturtle,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -309,7 +310,10 @@ def _jinjify_managed_files(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = run_jinjaturtle(jt_exe, artifact_path, role_name=role)
|
force_fmt = infer_other_formats(dest_path)
|
||||||
|
res = run_jinjaturtle(
|
||||||
|
jt_exe, artifact_path, role_name=role, force_format=force_fmt
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
# If jinjaturtle cannot process a file for any reason, skip silently.
|
# If jinjaturtle cannot process a file for any reason, skip silently.
|
||||||
# (Enroll's core promise is to be optimistic and non-interactive.)
|
# (Enroll's core promise is to be optimistic and non-interactive.)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue