fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Run multiple commands on single host in parallel


From: Brandon Whaley
Subject: Re: [Fab-user] Run multiple commands on single host in parallel
Date: Mon, 18 Jun 2018 16:57:21 -0400

Hi Rob, I've done this as a hack in the past by adding data to the host list and parsing it before execution to determine what to run.  I've built a simple example to give you an idea:

@task
def hostname():
    return run('hostname')

@task
def uname():
    return run('uname -a')

@task
def task_chooser():
    # only consider up to the first underscore to be host data
    host, task = env.host_string.split('_', 1)
    return execute(task, hosts=[host])[host]

@task
def parallel_runner():
    host_list=[
        'host1_hostname',
        'host1_uname',
        'host2_hostname',
        'host2_uname'
    ]
    with settings(parallel=True):
        execute(task_chooser, hosts=host_list)

[host1_hostname] Executing task 'task_chooser'
[host1_uname] Executing task 'task_chooser'
[host2_hostname] Executing task 'task_chooser'
[host2_uname] Executing task 'task_chooser'
[host2] Executing task 'uname'
[host2] Executing task 'hostname'
[host1] Executing task 'uname'
[host2] run: uname -a
[host1] Executing task 'hostname'
[host2] run: hostname
[host1] run: uname -a
[host1] run: hostname
[host1] out: Linux host1 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[host1] out:

[host2] out: host2
[host2] out:

[host2] out: Linux host2 4.4.0-63-generic #84-Ubuntu SMP Wed Feb 1 17:20:32 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[host2] out:

[host1] out: host1
[host1] out:


Done.


On Mon, Jun 18, 2018 at 3:00 PM Rob Marshall <address@hidden> wrote:
Hi,

I'm trying to run multiple commands on the same host in parallel but
if I try to run a list of commands based on env.host_string it doesn't
run those commands in parallel. Is there a way to do that?

I guess, in essence, I'd like to "nest" parallel commands. I
originally attempted to place the host in the hosts list multiple
times, but it looks like parallel removes duplicates (I assume this
has to do with separating results by host).

Thanks,

Rob

_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user

reply via email to

[Prev in Thread] Current Thread [Next in Thread]