标签:fabric
Fabric模块
fabric是基于paramiko模块封装开发的,paramiko更底层
安装,依赖pytcrypto,paramiko,要卸载python-pycrypto与python-paramiko
pip uninstall python-pycrypto
pip uninstall python-paramiko
pip uninstall pycrypto
yum install -y python-devel
一、安装fabric
[root@133 ~]# pip install pycrypto==‘2.3‘ [root@133 ~]# pip install paramiko==‘1.12.4‘ [root@133 ~]# pip install fabric==‘1.8.3‘ [root@133 ~]# pip list DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. ansible (2.1.0.0) backports.shutil-get-terminal-size (1.0.0) cffi (1.9.1) cryptography (1.7.2) decorator (4.0.11) Django (1.10.7) ecdsa (0.13) enum34 (1.1.6) Fabric (1.8.3) idna (2.2) ipaddress (1.0.18) ipython (5.3.0) ipython-genutils (0.2.0) Jinja2 (2.9.5) MarkupSafe (0.23) mysql-connector-python (2.1.1) MySQL-python (1.2.3) paramiko (1.12.4) pathlib2 (2.2.1) pexpect (4.2.1) pickleshare (0.7.4) pip (9.0.1) prompt-toolkit (1.0.14) ptyprocess (0.5.1) pyasn1 (0.2.2) pycparser (2.17) pycrypto (2.3) Pygments (2.2.0) PyYAML (3.12) scandir (1.5) setuptools (19.6) simplegeneric (0.8.1) site (0.0.1) six (1.10.0) traitlets (4.3.2) wcwidth (0.1.7) [root@133 ~]# python Python 2.7.3 (default, Jan 18 2017, 18:39:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import paramiko >>> import fabric >>>
二、fabric的使用
[root@133 managehosts]# vim fabfile.py from fabric.api import run def host_type(): run(‘uname -a‘) [root@133 managehosts]# fab -H 112.65.140.13 host_type [112.65.140.133] Executing task ‘host_type‘ [112.65.140.133] run: uname -a [112.65.140.133] out: Linux 133 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [112.65.140.133] out: Done. [root@133 managehosts]# vim fabfile.py from fabric.api import run, env env.hosts = [‘112.65.140.133‘,‘112.65.140.132‘] env.user = ‘root‘ env.password = ‘****‘ def host_type(): run(‘uname -a‘) [root@133 managehosts]# fab host_type [112.65.140.133] Executing task ‘host_type‘ [112.65.140.133] run: uname -a [112.65.140.133] out: Linux 133 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [112.65.140.133] out: [112.65.140.132] Executing task ‘host_type‘ [112.65.140.132] run: uname -a [112.65.140.132] out: Linux client 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [112.65.140.132] out: Done. Disconnecting from 112.65.140.133... done. Disconnecting from 112.65.140.132... done.
本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1919270
标签:fabric
原文地址:http://daixuan.blog.51cto.com/5426657/1919270