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 <rob.marshal...@gmail.com>
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
> Fab-user@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
_______________________________________________
Fab-user mailing list
Fab-user@nongnu.org
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to