myv myv2 是配置在/etc/hosts 的兩臺 虛擬機 虛擬機ip.html
官方文檔的例子不是給的很詳細..
http://docs.fabfile.org/en/1.13/usage/env.htmlpython
#!/usr/bin/env python # -*- coding: utf-8 -*- from fabric.api import * #只有 student@myv2 這個機器用的是密碼 env.hosts = ['gsx@myv','student@myv2','gsx@myv2'] # This dictionary is largely for internal use, and is filled automatically as a per-host-string password cache. Keys are full host strings and values are passwords (strings). env.passwords = { 'student@myv2:22':'1', } # http://docs.fabfile.org/en/1.13/usage/env.html # May be a string or list of strings, referencing file paths to SSH key files to try when connecting. Passed through directly to the SSH layer. May be set/appended to with -i. env.key_filename = ['~/.ssh/test','~/.ssh/test8'] def remoteRun(): print "ENV %s" %(env.hosts) out = run('whoami') print "Output %s"%(out) @hosts('gsx@myv2','gsx@myv') def taskSelectHost(): run('ifconfig')
fab -f ./multi_user_and_secret.py remoteRun taskSelectHost
student@myv 這個用戶是使用密碼登陸,單獨在 evn.passwords裏面配置. 注意配置的方式是 full host strings 即 用戶@IP:port 和 密碼.api
gsx@myv 使用 密鑰 ./ssh/test
gsx@myv2 使用 密鑰 ./ssh/test8app
將鏈接使用到的密鑰 填入 env.key_filename 列表中,密鑰填寫順序無關. 不須要hosts與 key_filename 對應起來, 也不須要長度相等 , fabric 會本身嘗試密鑰.(May be a string or list of strings, referencing file paths to SSH key files to try when connecting. Passed through directly to the SSH layer. May be set/appended to with -i.)ssh