|
|
@@ -1,7 +1,7 @@
|
|
|
import argparse
|
|
|
import os
|
|
|
|
|
|
-from .config import yaml_load,ConfigRoot
|
|
|
+from .config import yaml_load, ConfigRoot
|
|
|
from .main import get_hosts_and_tasks, run_batch, info
|
|
|
from .utils import (enable_logging_color, log_handler, logger, ByrdException,
|
|
|
ObjectDict, Env, abort)
|
|
|
@@ -10,7 +10,6 @@ basedir, _ = os.path.split(__file__)
|
|
|
PKG_DIR = os.path.join(basedir, 'pkg')
|
|
|
|
|
|
|
|
|
-
|
|
|
def load_cfg(path, prefix=None):
|
|
|
load_sections = ('networks', 'tasks', 'auth', 'env')
|
|
|
|
|
|
@@ -32,7 +31,6 @@ def load_cfg(path, prefix=None):
|
|
|
for k, v in cfg['tasks'].items():
|
|
|
v._cfg = cfg_cp
|
|
|
|
|
|
-
|
|
|
# Recursive load
|
|
|
if cfg.load:
|
|
|
cfg_path = os.path.dirname(path)
|
|
|
@@ -52,7 +50,7 @@ def load_cfg(path, prefix=None):
|
|
|
child_cfg = load_cfg(child_path, child_prefix)
|
|
|
key_fn = lambda x: '/'.join([child_prefix, x])
|
|
|
for section in load_sections:
|
|
|
- if not section in child_cfg:
|
|
|
+ if section not in child_cfg:
|
|
|
continue
|
|
|
items = {key_fn(k): v for k, v in child_cfg[section].items()}
|
|
|
cfg[section].update(items)
|
|
|
@@ -61,7 +59,7 @@ def load_cfg(path, prefix=None):
|
|
|
|
|
|
def load_cli(args=None):
|
|
|
parser = argparse.ArgumentParser()
|
|
|
- parser.add_argument('names', nargs='*',
|
|
|
+ parser.add_argument('names', nargs='*',
|
|
|
help='Hosts and commands to run them on')
|
|
|
parser.add_argument('-c', '--config', default='bd.yaml',
|
|
|
help='Config file')
|
|
|
@@ -98,6 +96,7 @@ def load_cli(args=None):
|
|
|
cli.env = dict(e.split('=') for e in cli.env)
|
|
|
return cli
|
|
|
|
|
|
+
|
|
|
def run():
|
|
|
cli = None
|
|
|
try:
|
|
|
@@ -114,9 +113,9 @@ def run():
|
|
|
return
|
|
|
|
|
|
base_env = Env(
|
|
|
- cli.env, # Highest-priority
|
|
|
+ cli.env, # Highest-priority
|
|
|
cli.cfg.get('env'),
|
|
|
- os.environ, # Lowest
|
|
|
+ os.environ, # Lowest
|
|
|
)
|
|
|
for task in cli.tasks:
|
|
|
run_batch(task, cli.hosts, cli, base_env)
|
|
|
@@ -125,5 +124,6 @@ def run():
|
|
|
raise
|
|
|
abort(str(e))
|
|
|
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
run()
|