我有以下 fabfile.py:
from fabric.api import env, run
host1 = '192.168.200.181'
host2 = '192.168.200.182'
host3 = '192.168.200.183'
env.hosts = [host1, host2, host3]
def df_h():
run("df -h | grep sda3")
我得到以下输出:
[192.168.200.181] run: df -h | grep sda3
[192.168.200.181] out: /dev/sda3 365G 180G 185G 50% /usr/local/nwe
[192.168.200.183] run: df -h | grep sda3
[192.168.200.183] out: /dev/sda3 365G 41G 324G 12% /usr/local/nwe
[192.168.200.182] run: df -h | grep sda3
[192.168.200.182] out: /dev/sda3 365G 87G 279G 24% /usr/local/nwe
Done.
Disconnecting from 192.168.200.182... done.
Disconnecting from 192.168.200.181... done.
Disconnecting from 192.168.200.183... done.
请注意,执行顺序与 env.hosts 规范不同。
为什么它会这样工作?有没有办法使执行顺序与 env.hosts 列表中指定的相同?