def run_ops(state, serial=False, no_wait=False):

    # Run all ops, but server by server
    if serial:
        for host in state.inventory:
            _run_server_ops(state, host.name)
        return

    # Run all the ops on each server in parallel (not waiting at each operation)
    elif no_wait:
        # Spawn greenlet for each host to run *all* ops
        greenlets = [
            state.pool.spawn(_run_server_ops, state, host.name)
            for host in state.inventory
        ]
        joinall(greenlets)
        return

    # Default: run all ops in order, waiting at each for all servers to complete
    for op_hash in state.op_order:
        op_meta = state.op_meta[op_hash]

        op_types = []
        if op_meta['serial']:
            op_types.append('serial')
        if op_meta['run_once']:
            op_types.append('run once')

        logger.info('{0} {1} {2}'.format(
            colored('Starting{0}operation:'.format(
                ' {0} '.format(', '.join(op_types)) if op_types else ' '
            ), 'blue'),
            colored(', '.join(op_meta['names']), attrs=['bold']),
            tuple(op_meta['args']) if op_meta['args'] else ''
        ))

        failed_hosts = set()

        if op_meta['serial']:
            # For each host, run the op
            for host in state.inventory:
                result = _run_op(state, host.name, op_hash)

                if not result:
                    failed_hosts.add(host.name)

        else:
            # Spawn greenlet for each host
            greenlet_hosts = [
                (host.name, state.pool.spawn(
                    _run_op, state, host.name, op_hash
                ))
                for host in state.inventory
            ]

            # Get all the results
            for (hostname, greenlet) in greenlet_hosts:
                if not greenlet.get():
                    failed_hosts.add(hostname)

        if not op_meta['ignore_errors']:
            state.fail_hosts(failed_hosts)

        if state.print_lines:
            print()
Runs all operations across all servers in a configurable manner.
dataset/ETHPy150Open Fizzadar/pyinfra/pyinfra/api/operations.py/run_ops