diff --git a/hadoop/plugin.py b/hadoop/plugin.py index 034b1d1cc797359fe461beb3acd4e607eb176e74..c9b52edf7432abd20d336c2e6991917017b799e8 100644 --- a/hadoop/plugin.py +++ b/hadoop/plugin.py @@ -36,11 +36,17 @@ class ComponentHadoop: with open('site2.pp', 'w') as f: f.write(site) - def init_commands(self): - return [ - ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=site.pp dest=/root', 'all'], - ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=site2.pp dest=/root', 'all'], - ] + def commands(self, action): + if action == 'init': + return [ + ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=site.pp dest=/root', 'all'], + ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=site2.pp dest=/root', 'all'], + ] + elif action == 'deployment': + return [ + ['ansible', '-i', './inventory', '-m', 'shell', '-a', 'puppet apply --test /root/site.pp >> stage1.log 2>&1; echo $?', 'all'], + ['ansible', '-i', './inventory', '-m', 'shell', '-a', 'puppet apply --test /root/site2.pp >> stage2.log 2>&1; echo $?', 'all'], + ] class Component(ComponentHadoop): diff --git a/orchestrate.py b/orchestrate.py index 0f8d7960af54e95540b4da3c3b8c265fa16edc38..c1e41efe674cd75b3f67b3b03a4eb666bfdab9c8 100755 --- a/orchestrate.py +++ b/orchestrate.py @@ -8,7 +8,7 @@ import subprocess import sys import time -DEFAULT_ACTIONS = ['files', 'ping', 'init', 'wait'] +DEFAULT_ACTIONS = ['files', 'ping', 'init', 'wait', 'deployment'] parser = argparse.ArgumentParser(description='terraform cluster orchestrator') parser.add_argument('-c', '--config', @@ -110,7 +110,7 @@ if 'ping' in args.actions: ret = subprocess.call(cmd) time.sleep(2) print('') - print('-> sleep %d' % 10 + 5 * n) + print('-> sleep %d' % (10 + 5 * n)) time.sleep(10 + 5 * n) if component: component.action('ping') @@ -139,7 +139,7 @@ if 'init' in args.actions: ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=hosts dest=/etc/hosts', 'nodes'], ] if component: - commands += component.init_commands() + commands += component.commands('init') for cmd in commands: print('-> %s' % ' '.join(cmd)) @@ -163,3 +163,17 @@ if 'wait' in args.actions: subprocess.run(cmd) if component: component.action('wait') + +if 'deployment' in args.actions: + print('== deployment ==') + + commands = [] + if component: + commands += component.commands('deployment') + + for cmd in commands: + print('-> %s' % ' '.join(cmd)) + if not args.dry_run: + subprocess.run(cmd) + if component: + component.action('deployment')