commit e068ac650abba848e0604a8fe96b2a93a9c32dc4
parent 8cebcb161f22f232a0a5e261fe17ff29083e4f78
Author: Asher Morgan <asher@ashermorgan.net>
Date: Sun, 23 Aug 2026 13:50:59 -0700
Reorganize playbook config file
Replace "playbook" property with optional "path" option that defaults to
the playbook name. The default playbook is now "main.yml".
Diffstat:
3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/aoh/client.py b/aoh/client.py
@@ -174,7 +174,7 @@ def cli(args):
print()
print('Arguments: ')
print(' playbook The name of the playbook to run (defaults '
- 'to "main")')
+ 'to "main.yml")')
print()
print('Options: ')
print(' -h, --help Show this help message and exit')
@@ -187,7 +187,7 @@ def cli(args):
playbook = args[1]
aoh_args = args[2:]
else:
- playbook = 'main'
+ playbook = 'main.yml'
aoh_args = args[1:]
create_runner(playbook, aoh_args)
diff --git a/aoh/playbook.py b/aoh/playbook.py
@@ -1,3 +1,4 @@
+import os
import tempfile
import ansible_runner
@@ -71,11 +72,11 @@ class PlaybookError(Exception):
class Playbook:
- def __init__(self, dict):
+ def __init__(self, name, dict):
"""Parse a playbook configuration from a dictionary."""
_types = {
- 'playbook': str,
+ 'path': str,
'config': str,
'cmdline': str,
'output': bool,
@@ -84,14 +85,11 @@ class Playbook:
'block_opts': list,
}
- if 'playbook' not in dict:
- raise PlaybookError('"playbook" field missing')
-
for key, _type in _types.items():
if key in dict and type(dict[key]) != _type:
raise PlaybookError(f'"{key}" field must be of type {_type}')
- self.playbook = dict['playbook']
+ self.path = dict.get('path', name)
self.config = dict.get('config', None)
self.cmdline = dict.get('cmdline', '')
self.output = dict.get('output', True)
@@ -99,6 +97,10 @@ class Playbook:
self.allow_opts = dict.get('allow_opts', [])
self.block_opts = dict.get('block_opts', [])
+ # TODO: allow a default playbook dir to be specified?
+ self.path = os.path.abspath(self.path)
+ self.config = os.path.abspath(self.config)
+
def validate_args(self, args):
"""Determine if arguments pass the playbook's security policies."""
@@ -144,12 +146,12 @@ class Playbook:
return list(pw_types)
-def get_playbook(playbook):
+def get_playbook(name):
"""Lookup a playbook configuration."""
with open(CONFIG_FILE, 'r') as f:
CONFIG = yaml.safe_load(f)
- if playbook in CONFIG:
- return Playbook(CONFIG[playbook])
+ if name in CONFIG:
+ return Playbook(name, CONFIG[name])
else:
return None
diff --git a/aoh/runner.py b/aoh/runner.py
@@ -121,7 +121,7 @@ class Runner:
extravars=vars,
cmdline=cmdline,
passwords=pw_prompt_answers,
- playbook=self.playbook.playbook,
+ playbook=self.playbook.path,
quiet=True,
suppress_env_files=True,
)