Linux自动化运维第一步,fabric的安装与初次体验
使用python3的请安装fabric3:pip install fabric3
这样使用和 fabric 1.14版本一样,不,fabric3的版本就是1.14
使用python2的请安装fabric 1.14版本的,因为现阶段能找到的几乎都是fabric 1.14的资料;pip install fabric==1.14
若是是pip install fabric安装,则会安装到fabric 2.0以上版本,使用姿势大不一样。
单台主机请使用env.host_string字段来指定主机,否则会问你要主机名(IP地址);
import fabric.api fabric.api.env.password = 'Lovedan@971220' fabric.api.env.host_string = '192.168.50.25' fabric.api.env.port = "22" fabric.api.env.user = 'root' def test(): fabric.api.run('ls / -al') with fabric.api.cd('/home'): fabric.api.run('pwd;ls -al') test()