biiiiig refactor to support jinjaturtle and multi site mode
This commit is contained in:
parent
576649a49c
commit
f255ba566c
11 changed files with 1331 additions and 298 deletions
|
|
@ -1,10 +1,37 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
from .harvest import harvest
|
||||
from .manifest import manifest
|
||||
|
||||
|
||||
def _add_common_manifest_args(p: argparse.ArgumentParser) -> None:
|
||||
p.add_argument(
|
||||
"--fqdn",
|
||||
help="Host FQDN/name for site-mode output (creates inventory/, inventory/host_vars/, playbooks/).",
|
||||
)
|
||||
g = p.add_mutually_exclusive_group()
|
||||
g.add_argument(
|
||||
"--jinjaturtle",
|
||||
action="store_true",
|
||||
help="Attempt jinjaturtle template integration (it will error if jinjaturtle is not found on PATH).",
|
||||
)
|
||||
g.add_argument(
|
||||
"--no-jinjaturtle",
|
||||
action="store_true",
|
||||
help="Do not use jinjaturtle integration, even if it is installed.",
|
||||
)
|
||||
|
||||
|
||||
def _jt_mode(args: argparse.Namespace) -> str:
|
||||
if getattr(args, "jinjaturtle", False):
|
||||
return "on"
|
||||
if getattr(args, "no_jinjaturtle", False):
|
||||
return "off"
|
||||
return "auto"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser(prog="enroll")
|
||||
sub = ap.add_subparsers(dest="cmd", required=True)
|
||||
|
|
@ -23,9 +50,10 @@ def main() -> None:
|
|||
required=True,
|
||||
help="Output directory for generated roles/playbook Ansible manifest",
|
||||
)
|
||||
_add_common_manifest_args(r)
|
||||
|
||||
e = sub.add_parser(
|
||||
"enroll", help="Harvest state, then manifest Ansible code, in one shot"
|
||||
"single-shot", help="Harvest state, then manifest Ansible code, in one shot"
|
||||
)
|
||||
e.add_argument(
|
||||
"--harvest", required=True, help="Path to the directory to place the harvest in"
|
||||
|
|
@ -35,6 +63,7 @@ def main() -> None:
|
|||
required=True,
|
||||
help="Output directory for generated roles/playbook Ansible manifest",
|
||||
)
|
||||
_add_common_manifest_args(e)
|
||||
|
||||
args = ap.parse_args()
|
||||
|
||||
|
|
@ -42,7 +71,7 @@ def main() -> None:
|
|||
path = harvest(args.out)
|
||||
print(path)
|
||||
elif args.cmd == "manifest":
|
||||
manifest(args.harvest, args.out)
|
||||
elif args.cmd == "enroll":
|
||||
manifest(args.harvest, args.out, fqdn=args.fqdn, jinjaturtle=_jt_mode(args))
|
||||
elif args.cmd == "single-shot":
|
||||
harvest(args.harvest)
|
||||
manifest(args.harvest, args.out)
|
||||
manifest(args.harvest, args.out, fqdn=args.fqdn, jinjaturtle=_jt_mode(args))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue