Commit a08f5582 by Gabe Mulley

fix remote task execution

* Fix an accidentally committed syntax error in task.yml
* Vastly improve the argument parsing situation, now you can just pass in all of the arguments as you would to launch-task, and remote-task will pass those through.
parent 68754b75
"""Remote Task
Usage:
remote-task [--job-flow-id=ID] [--branch=BRANCH] [--repo=REPO] [--name=NAME] [--verbose] [<launch-task-args>]
Options:
--job-flow-id=ID EMR job flow to run the task
--branch=BRANCH git branch to checkout before running the task [default: release]
--repo=REPO git repository to clone
--name=NAME an identifier for this task
--verbose display very verbose output
<launch-task-args> a single-quoted string of arguments to pass-through to launch-task on the remote machine
"""
import argparse
import os import os
from subprocess import Popen from subprocess import Popen
import sys import sys
import uuid import uuid
from docopt import docopt
def main(): def main():
arguments = docopt(__doc__) parser = argparse.ArgumentParser()
parser.add_argument('--job-flow-id', help='EMR job flow to run the task')
parser.add_argument('--branch', help='git branch to checkout before running the task', default='release')
parser.add_argument('--repo', help='git repository to clone')
parser.add_argument('--remote-name', help='an identifier for this remote task')
parser.add_argument('--verbose', action='store_true', help='display very verbose output')
arguments, extra_args = parser.parse_known_args()
arguments.launch_task_arguments = extra_args
change_directory_to_ansible_script_home() change_directory_to_ansible_script_home()
extra_vars = convert_cli_arguments_to_ansible_extra_vars(arguments) extra_vars = convert_cli_arguments_to_ansible_extra_vars(arguments)
run_ansible_playbook(arguments.get('--verbose', False), extra_vars) run_ansible_playbook(arguments.verbose, extra_vars)
def change_directory_to_ansible_script_home(): def change_directory_to_ansible_script_home():
...@@ -36,15 +28,15 @@ def change_directory_to_ansible_script_home(): ...@@ -36,15 +28,15 @@ def change_directory_to_ansible_script_home():
def convert_cli_arguments_to_ansible_extra_vars(arguments): def convert_cli_arguments_to_ansible_extra_vars(arguments):
uid = arguments.get('--name') or str(uuid.uuid4()) uid = arguments.remote_name or str(uuid.uuid4())
extra_vars = { extra_vars = {
'name': arguments['--job-flow-id'], 'name': arguments.job_flow_id,
'branch': arguments.get('--branch', 'release'), 'branch': arguments.branch,
'task_arguments': arguments.get('<launch-task-args>', '') + ' >/tmp/{0}.out 2>/tmp/{0}.err'.format(uid), 'task_arguments': ' '.join(arguments.launch_task_arguments) + ' >/tmp/{0}.out 2>/tmp/{0}.err'.format(uid),
'uuid': uid, 'uuid': uid,
} }
if arguments['--repo']: if arguments.repo:
extra_vars['repo'] = arguments['--repo'] extra_vars['repo'] = arguments.repo
return ' '.join(["{}='{}'".format(k, extra_vars[k]) for k in extra_vars]) return ' '.join(["{}='{}'".format(k, extra_vars[k]) for k in extra_vars])
...@@ -60,7 +52,6 @@ def run_ansible_playbook(verbose, extra_vars): ...@@ -60,7 +52,6 @@ def run_ansible_playbook(verbose, extra_vars):
env.update({ env.update({
'ANSIBLE_SSH_ARGS': '-o ForwardAgent=yes' 'ANSIBLE_SSH_ARGS': '-o ForwardAgent=yes'
}) })
with open('/dev/null', 'rw') as devnull: with open('/dev/null', 'rw') as devnull:
proc = Popen(command, stdin=devnull, env=env) proc = Popen(command, stdin=devnull, env=env)
proc.communicate() proc.communicate()
...@@ -4,6 +4,5 @@ pbr==0.5.23 ...@@ -4,6 +4,5 @@ pbr==0.5.23
stevedore==0.13 stevedore==0.13
tornado==3.1.1 tornado==3.1.1
ansible==1.4.4 ansible==1.4.4
docopt==0.6.1
-e git+https://github.com/spotify/luigi.git@a33756c781b9bf7e51384f0eb19d6a25050ef136#egg=luigi -e git+https://github.com/spotify/luigi.git@a33756c781b9bf7e51384f0eb19d6a25050ef136#egg=luigi
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
- task_arguments: '' - task_arguments: ''
- git_server_hostname: github.com - git_server_hostname: github.com
- git_server_ip_address: 207.97.227.239 - git_server_ip_address: 207.97.227.239
- git_server_public_key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='' - git_server_public_key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
tasks: tasks:
- name: known_hosts file exists - name: known_hosts file exists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment