Fabric


~/.ssh/configで多段sshの設定と、use_ssh_configを組み合わせると切断されない

/.ssh/configで多段sshの設定と、use_ssh_configを組み合わせると処理が終わっても切断されない。
バグっぽい


fabricからスクリプトが起動しない場合

fabricからシェルスクリプト等を実行する時、起動しないものがある


fabtools


実行時に処理が進まない場合


gateway: 多段SSH


env.roledefs/@roles : 環境別設定


@runs_onceデコレータ


quiet() : エラーが発生した場合でも表示しない

@task
def test_quiet():
    with quiet():
        print local("test -e /tmp/build").succeeded # False
        print local("test -e /tmp/build").failed # True

return_codeの取得

@task
def test_return():
    print local('test -d /tmp', quiet=True, warn_only=True).succeeded   # True
    print local('test -d /tmp', quiet=True, warn_only=True).return_code # 0

環境変数の設定


with構文

@task
def test_cd():
    with cd('/tmp'):
        run('pwd') # /tmp

文字列をbool型に変換

import distutils

print distutils.util.strtobool("true")  # 1: y, yes, t, true, on
print distutils.util.strtobool("false") # 0: n, no, f, false, off
var1 = distutils.util.strtobool(var1) if isinstance(var1, str) else var1

公開鍵認証での接続

def test():
    env.use_ssh_config = True # ~/.ssh/configを参照する場合
    env.user           = "hoge"
    env.key_filename   = "/home/hoge/.ssh/id_rsa"
    run("hostname -s")

Exception : エラーと例外


logging : ログの出力


env.hosts : ホストの指定


fabricrc : 設定ファイル


env : 環境変数

env.varname に対して、読み書き可能。省略時のデフォルトとして使われる。
env.newvar="value" のように新しい値も作成できる。
envは辞書型


AssertionError


confirm: Yes/No確認


prompt: ユーザ入力待ち


rootユーザで実行


関数と引数


clouddns:Python API binding to Rackspace Cloud DNS


boto:A Python interface to Amazon Web Services


@taskデコレータ


git/svn無視ファイル


再インストール/アップグレード


インストール


Raspbian 7.x

cat /etc/debian_version 
7.1

python -V
Python 2.7.3

sudo aptitude update
sudo aptitude install python-pip python-dev gcc
sudo pip-2.7 install fabric fabtools fexpect
sudo pip-2.7 install -U distribute

CentOS 6.x

vim fabfile.py
----
# -*- coding: utf-8 -*-
from fabric.api import *

@task
def host_type() :
    """ usage """
    run('uname -s');
# vim: ts=4 sw=4 expandtab
----

fab -H localhost host_type
out: Linux

fab list
Available commands:
    host_type              usage

CentOS 5.x


添付ファイル: filegateway_test.py 1762件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-09-15 (土) 07:31:37