Fabric Env.hosts Not Being Identified
I have a simple fabfile by the name env_fabfile.py # env_fabfile.py # makes use of fab env variables from fabric.api import env, run def login(): env.hosts = ['user@host1:12
Solution 1:
The short answer is that you shouldn't set the env.hosts
value the way you are currently doing, and env.passowrds
is super-sketchy (broken maybe?), and it's recommended to use SSH key-based access, especially leveraging native SSH config files.
Here's the modified version of your timecal.py script which works as expected, and I'll call out some of the differences below.
# timecal.py# runs the fabfile once in serial and calculates the time# then runs the same file in parallel and calculates the timefrom fabric.api import env, run, execute, parallel
import time
env.use_ssh_config = True
env.roledefs = {
"my_servers": ['server_1', 'server_2']
}
defrun_lsb_release():
print"in run"
run('lsb_release -a')
defdo_task(task_func):
start_time = time.time()
execute(task_func, roles=['my_servers'])
elapsed_time = time.time() - start_time
return elapsed_time
if __name__ == '__main__':
print"Running in serial mode "print"Total time taken ", do_task(run_lsb_release)
print"Running in parallel mode"print"Total time taken ", do_task(parallel(run_lsb_release))
The main difference is using env.roledefs
, and the SSH config file, rather than hosts & passwords. Those values will NOT work in the parallel execution mode, due to the fact that those tasks are executed in separate threads. The docs are a little thin, but that's basically why you're having this problem.
Post a Comment for "Fabric Env.hosts Not Being Identified"