LoginSignup
13
8

More than 5 years have passed since last update.

fabricの導入方法と基本的な使い方

Posted at

python製のデプロイツールfabricの導入方法と使い方。
CentOSなどyumが使えるOSが前提。

導入方法

必要なパッケージをインストール。

yum install gcc python-devel python-setuptools
easy_install pip
pip install fabric

インストールされたことを確認。

fab -V

コマンド実行

リモートサーバーに対してコマンドを実行してシステム情報を取得する。
sshでホスト名を指定して接続ができることが前提。
(./ssh/configファイルを設定するなど)

fabfileを作成する。

from fabric.api import run, env

env.use_ssh_config = True

def uname():
    run("uname")

fabコマンドを実行する。
(hostnameにホスト名を指定)

fab -H hostname uname

おまけ

#リモートサーバーでコマンド実行
run("コマンド")

#ローカルサーバーでコマンド実行
local("コマンド")

#リモートサーバーにファイル送信
put("{送信元のファイルパス}", "{送信先のファイルパス}")

#リモートサーバーからファイル受信
get("{送信元のファイルパス}", "{送信先のファイルパス}")

各コマンドを実行する際にモジュールを先に指定する。

from fabric.api import run, env, local, put, get
13
8
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
8