Discussion:
[Fab-user] Parallel Tasks With Different Parameters
Erikton Konomi
2016-12-08 22:53:16 UTC
Permalink
Hello,

How would you go about running multiple tasks on multiple hosts but with
different parameter for each host? For example a fabfile with:

@parallel
def task(param):
run("some command that takes <param> as argument")

def launcher():
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
<param> for each host, like:
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])

Is this functionality there? I couldn't find something on the documents.

Thanks,
Erik
Brandon Whaley
2016-12-08 23:46:28 UTC
Permalink
That functionality is not built in to fabric. Either have your task query
for what param it should use based on the value of env.host_string or abuse
host strings to pass the arguments like so:

@parallel
def task():
#naturally requires that param not contain '_', use another non-valid
host character if it needs to
host_string, param = env.host_string.split('_')
with settings(host_string=host_string):
run("command with {}".format(param))

def launcher():
execute(task, hosts=['192.168.1.100_param1', '192.168.1.200_param2'])
Post by Erikton Konomi
Hello,
How would you go about running multiple tasks on multiple hosts but with
@parallel
run("some command that takes <param> as argument")
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])
Is this functionality there? I couldn't find something on the documents.
Thanks,
Erik
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Erikton Konomi
2016-12-09 19:04:44 UTC
Permalink
Thanks Brandon! This is very helpful.
Post by Brandon Whaley
That functionality is not built in to fabric. Either have your task query
for what param it should use based on the value of env.host_string or abuse
@parallel
#naturally requires that param not contain '_', use another non-valid
host character if it needs to
host_string, param = env.host_string.split('_')
run("command with {}".format(param))
execute(task, hosts=['192.168.1.100_param1', '192.168.1.200_param2'])
Post by Erikton Konomi
Hello,
How would you go about running multiple tasks on multiple hosts but with
@parallel
run("some command that takes <param> as argument")
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])
Is this functionality there? I couldn't find something on the documents.
Thanks,
Erik
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Brandon Whaley
2016-12-09 19:05:47 UTC
Permalink
Glad to help!
Post by Erikton Konomi
Thanks Brandon! This is very helpful.
That functionality is not built in to fabric. Either have your task query
for what param it should use based on the value of env.host_string or abuse
@parallel
#naturally requires that param not contain '_', use another non-valid
host character if it needs to
host_string, param = env.host_string.split('_')
run("command with {}".format(param))
execute(task, hosts=['192.168.1.100_param1', '192.168.1.200_param2'])
Hello,
How would you go about running multiple tasks on multiple hosts but with
@parallel
run("some command that takes <param> as argument")
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])
Is this functionality there? I couldn't find something on the documents.
Thanks,
Erik
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Nick Timkovich
2016-12-09 21:33:11 UTC
Permalink
I like Brandon's first notion: "have your task query for what param it
should use based on the value of env.host_string", which seems like a much
better idea than the second that he gave an example for. I might be barking
up the wrong tree, but would something like the following work?

@parallel
def task(param_table):
param = param_table[env.host_string]
run("command with {}".format(param))

def launcher():
param_table = {
'192.168.1.100': 'param1',
'192.168.1.200': 'param2',
}
execute(task, param_table, hosts=list(param_table))
Post by Brandon Whaley
Glad to help!
Post by Erikton Konomi
Thanks Brandon! This is very helpful.
That functionality is not built in to fabric. Either have your task
query for what param it should use based on the value of env.host_string or
@parallel
#naturally requires that param not contain '_', use another non-valid
host character if it needs to
host_string, param = env.host_string.split('_')
run("command with {}".format(param))
execute(task, hosts=['192.168.1.100_param1', '192.168.1.200_param2'])
Hello,
How would you go about running multiple tasks on multiple hosts but with
@parallel
run("some command that takes <param> as argument")
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])
Is this functionality there? I couldn't find something on the documents.
Thanks,
Erik
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Brandon Whaley
2016-12-09 21:41:42 UTC
Permalink
Yes Nick, that's a good example implementation. You could also pull from a
database or load a config file with the info.
Post by Nick Timkovich
I like Brandon's first notion: "have your task query for what param it
should use based on the value of env.host_string", which seems like a much
better idea than the second that he gave an example for. I might be barking
up the wrong tree, but would something like the following work?
@parallel
param = param_table[env.host_string]
run("command with {}".format(param))
param_table = {
'192.168.1.100': 'param1',
'192.168.1.200': 'param2',
}
execute(task, param_table, hosts=list(param_table))
Glad to help!
Thanks Brandon! This is very helpful.
That functionality is not built in to fabric. Either have your task query
for what param it should use based on the value of env.host_string or abuse
@parallel
#naturally requires that param not contain '_', use another non-valid
host character if it needs to
host_string, param = env.host_string.split('_')
run("command with {}".format(param))
execute(task, hosts=['192.168.1.100_param1', '192.168.1.200_param2'])
Hello,
How would you go about running multiple tasks on multiple hosts but with
@parallel
run("some command that takes <param> as argument")
execute(task, param_1, hosts=['192.168.1.100', '192.168.1.200'])
# The above will run the task on 2 hosts but with the same value for
<param>
# I would like to run both hosts but specifying different value for
# execute(task, args=[param_1, param_2], hosts=['192.168.1.100',
'192.168.1.200'])
Is this functionality there? I couldn't find something on the documents.
Thanks,
Erik
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...