読者です 読者をやめる 読者になる 読者になる

Python Fabric を入れてみる。

ちょっと、自動化の下調べに、Fabric を、Mac OSX 10.7.5 にいれてみる。

いまは、homebrew で、構築してあるので、pipで、入れる。

MBA:~ guutara$ pip install Fabric
Downloading/unpacking Fabric
  Downloading Fabric-1.6.0.tar.gz (215kB): 215kB downloaded
  Running setup.py egg_info for package Fabric
    
    warning: no previously-included files matching '*' found under directory 'docs/_build'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
Downloading/unpacking paramiko>=1.10.0 (from Fabric)
  Downloading paramiko-1.10.0.tar.gz (822kB): 822kB downloaded
  Running setup.py egg_info for package paramiko
    
Downloading/unpacking pycrypto>=2.1,!=2.4 (from paramiko>=1.10.0->Fabric)
  Downloading pycrypto-2.6.tar.gz (443kB): 443kB downloaded
  Running setup.py egg_info for package pycrypto
    
Installing collected packages: Fabric, paramiko, pycrypto
  Running setup.py install for Fabric
    
    warning: no previously-included files matching '*' found under directory 'docs/_build'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    Installing fab script to /usr/local/share/python
  Running setup.py install for paramiko
    
  Running setup.py install for pycrypto
    checking for gcc... gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables...
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking for __gmpz_init in -lgmp... no
    checking for __gmpz_init in -lmpir... no
    checking whether mpz_powm is declared... no
    checking whether mpz_powm_sec is declared... no
    checking how to run the C preprocessor... gcc -E
    checking for grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking for inttypes.h... (cached) yes
    checking limits.h usability... yes
    checking limits.h presence... yes
    checking for limits.h... yes
    checking stddef.h usability... yes
    checking stddef.h presence... yes
    checking for stddef.h... yes
    checking for stdint.h... (cached) yes
    checking for stdlib.h... (cached) yes
    checking for string.h... (cached) yes
    checking wchar.h usability... yes
    checking wchar.h presence... yes
    checking for wchar.h... yes
    checking for inline... inline
    checking for int16_t... yes
    checking for int32_t... yes
    checking for int64_t... yes
    checking for int8_t... yes
    checking for size_t... yes
    checking for uint16_t... yes
    checking for uint32_t... yes
    checking for uint64_t... yes
    checking for uint8_t... yes
    checking for stdlib.h... (cached) yes
    checking for GNU libc compatible malloc... yes
    checking for memmove... yes
    checking for memset... yes
    configure: creating ./config.status
    config.status: creating src/config.h
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    building 'Crypto.Hash._MD2' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.7-x86_64-2.7/src/MD2.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/MD2.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_MD2.so
    building 'Crypto.Hash._MD4' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD4.c -o build/temp.macosx-10.7-x86_64-2.7/src/MD4.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/MD4.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_MD4.so
    building 'Crypto.Hash._SHA256' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/SHA256.c -o build/temp.macosx-10.7-x86_64-2.7/src/SHA256.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/SHA256.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_SHA256.so
    building 'Crypto.Hash._SHA224' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/SHA224.c -o build/temp.macosx-10.7-x86_64-2.7/src/SHA224.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/SHA224.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_SHA224.so
    building 'Crypto.Hash._SHA384' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/SHA384.c -o build/temp.macosx-10.7-x86_64-2.7/src/SHA384.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/SHA384.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_SHA384.so
    building 'Crypto.Hash._SHA512' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/SHA512.c -o build/temp.macosx-10.7-x86_64-2.7/src/SHA512.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/SHA512.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_SHA512.so
    building 'Crypto.Hash._RIPEMD160' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -DPCT_LITTLE_ENDIAN=1 -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/RIPEMD160.c -o build/temp.macosx-10.7-x86_64-2.7/src/RIPEMD160.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/RIPEMD160.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Hash/_RIPEMD160.so
    building 'Crypto.Cipher._AES' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/AES.c -o build/temp.macosx-10.7-x86_64-2.7/src/AES.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/AES.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_AES.so
    building 'Crypto.Cipher._ARC2' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/ARC2.c -o build/temp.macosx-10.7-x86_64-2.7/src/ARC2.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/ARC2.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_ARC2.so
    building 'Crypto.Cipher._Blowfish' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/Blowfish.c -o build/temp.macosx-10.7-x86_64-2.7/src/Blowfish.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/Blowfish.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_Blowfish.so
    building 'Crypto.Cipher._CAST' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/CAST.c -o build/temp.macosx-10.7-x86_64-2.7/src/CAST.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/CAST.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_CAST.so
    building 'Crypto.Cipher._DES' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -Isrc/libtom/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/DES.c -o build/temp.macosx-10.7-x86_64-2.7/src/DES.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/DES.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_DES.so
    building 'Crypto.Cipher._DES3' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -Isrc/libtom/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/DES3.c -o build/temp.macosx-10.7-x86_64-2.7/src/DES3.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/DES3.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_DES3.so
    building 'Crypto.Cipher._ARC4' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/ARC4.c -o build/temp.macosx-10.7-x86_64-2.7/src/ARC4.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/ARC4.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_ARC4.so
    building 'Crypto.Cipher._XOR' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/XOR.c -o build/temp.macosx-10.7-x86_64-2.7/src/XOR.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/XOR.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Cipher/_XOR.so
    building 'Crypto.Util.strxor' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/strxor.c -o build/temp.macosx-10.7-x86_64-2.7/src/strxor.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/strxor.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Util/strxor.so
    building 'Crypto.Util._counter' extension
    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/_counter.c -o build/temp.macosx-10.7-x86_64-2.7/src/_counter.o
    cc -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.7-x86_64-2.7/src/_counter.o -o build/lib.macosx-10.7-x86_64-2.7/Crypto/Util/_counter.so
    
Successfully installed Fabric paramiko pycrypto
Cleaning up...

MBA:~ guutara$ fab

Fatal error: Couldn't find any fabfiles!

Remember that -f can be used to specify fabfile path, and use -h for help.

Aborting.

MBA:~ guutara$ which fab
/usr/local/share/python/fab
MBA-20120331:~ guutara$ ls /usr/local/share/
aclocal	doc	gnupg	locale	man	python
MBA-20120331:~ guutara$ ls /usr/local/share/python/
Extras/                rst2latex.py           rst2pseudoxml.py       rstpep2html.py         sphinx-quickstart
fab                    rst2man.py             rst2s5.py              sphinx-apidoc          
pygmentize             rst2odt.py             rst2xetex.py           sphinx-autogen         
rst2html.py            rst2odt_prepstyles.py  rst2xml.py             sphinx-build           
MBA:~ guutara$ ls -al /usr/local/share/python/fab 
-rwxr-xr-x  1 guutara  admin  389  3 13 15:01 /usr/local/share/python/fab
MBA:~ guutara$ 

/usr/local/share/python/ 配下に、インストールされてる。
そういえば、sphinx も、そうだったっけ。

fabric.py を、とりあえず、書いて実行してみた。
bsd系につないだので、env.shell を書き直した。。

from fabric.api import env,run

env.hosts = ['xxxxxx.sakura.ne.jp']
env.user = "xxxxxx"
env.password = "yyyyyyyy"
env.shell = "/usr/local/bin/bash -l -c "

def hello():
    run("echo `hostname`")

実行結果

MBA-20120331:fabric guutara$ fab hello
[xxxxxx.sakura.ne.jp] Executing task 'hello'
[xxxxxx.sakura.ne.jp] run: echo `hostname`
[xxxxxx.sakura.ne.jp] out: zzzz.sakura.ne.jp
[xxxxxx.sakura.ne.jp] out: 


Done.
Disconnecting from xxxxxx.sakura.ne.jp... done.

簡単だ。。
昔のオートパイロットみたいだなぁ。。