Exemple #1
0
def run_tasks(task_list):
    for name, args, kwargs, arg_hosts, arg_roles, arg_excl_hosts in task_list:
        try:
            nodeps_tasks = [
                'package.install', 'server.uninstall', 'server.install',
                'server.upgrade'
            ]
            if state.env.nodeps and name.strip() not in nodeps_tasks:
                sys.stderr.write('Invalid argument --nodeps to task: %s\n' %
                                 name)
                display_command(name, 2)

            return execute(name,
                           hosts=state.env.hosts,
                           roles=arg_roles,
                           exclude_hosts=state.env.exclude_hosts,
                           *args,
                           **kwargs)
        except TypeError as e:
            if is_arguments_error(e):
                print("Incorrect number of arguments to task.\n")
                _LOGGER.error('Incorrect number of arguments to task',
                              exc_info=True)
                display_command(name, 2)
            else:
                raise
        except BaseException as e:
            raise
Exemple #2
0
def run_tasks(task_list):
    for name, args, kwargs, arg_hosts, arg_roles, arg_excl_hosts in task_list:
        try:
            nodeps_tasks = ['package.install', 'server.uninstall',
                            'server.install', 'server.upgrade']
            if state.env.nodeps and name.strip() not in nodeps_tasks:
                sys.stderr.write('Invalid argument --nodeps to task: %s\n'
                                 % name)
                display_command(name, 2)

            return execute(
                name,
                hosts=state.env.hosts,
                roles=arg_roles,
                exclude_hosts=state.env.exclude_hosts,
                *args, **kwargs
            )
        except TypeError as e:
            if is_arguments_error(e):
                print("Incorrect number of arguments to task.\n")
                _LOGGER.error('Incorrect number of arguments to task',
                              exc_info=True)
                display_command(name, 2)
            else:
                raise
        except BaseException as e:
            raise
Exemple #3
0
        # If running in parallel, block until job queue is emptied
        if jobs:
            jobs.close()
            # Abort if any children did not exit cleanly (fail-fast).
            # This prevents Fabric from continuing on to any other tasks.
            # Otherwise, pull in results from the child run.
            ran_jobs = jobs.run()
            for name, d in ran_jobs.iteritems():
                if d['exit_code'] != 0:
                    if isinstance(d['results'], NetworkError):
                        func = warn if state.env.skip_bad_hosts \
                            or state.env.warn_only else abort
                        error(d['results'].message,
                              exception=d['results'].wrapped,
                              func=func)
                    elif exception.is_arguments_error(d['results']):
                        raise d['results']
                    elif isinstance(d['results'], SystemExit):
                        # System exit indicates abort
                        pass
                    elif isinstance(d['results'], BaseException):
                        error(d['results'].message, exception=d['results'])
                    else:
                        error('One or more hosts failed while executing task.')
                results[name] = d['results']

    # Or just run once for local-only
    else:
        with settings(**my_env):
            results['<local-only>'] = task.run(*args, **new_kwargs)
    # Return what we can from the inner task executions
        # If running in parallel, block until job queue is emptied
        if jobs:
            jobs.close()
            # Abort if any children did not exit cleanly (fail-fast).
            # This prevents Fabric from continuing on to any other tasks.
            # Otherwise, pull in results from the child run.
            ran_jobs = jobs.run()
            for name, d in ran_jobs.iteritems():
                if d['exit_code'] != 0:
                    if isinstance(d['results'], NetworkError):
                        func = warn if state.env.skip_bad_hosts \
                            or state.env.warn_only else abort
                        error(d['results'].message,
                              exception=d['results'].wrapped, func=func)
                    elif exception.is_arguments_error(d['results']):
                        raise d['results']
                    elif isinstance(d['results'], SystemExit):
                        # System exit indicates abort
                        pass
                    elif isinstance(d['results'], BaseException):
                        error(d['results'].message, exception=d['results'])
                    else:
                        error('One or more hosts failed while executing task.')
                results[name] = d['results']

    # Or just run once for local-only
    else:
        with settings(**my_env):
            results['<local-only>'] = task.run(*args, **new_kwargs)
    # Return what we can from the inner task executions