LoginSignup
3
3

More than 5 years have passed since last update.

fabric を python 内でそのまま使う(fabric3)

Last updated at Posted at 2016-10-05

通常のスクリプト内から、fabric を簡単に使えることがわかったので、
メモ的に書いておきます。

jupyter から、使うと結構便利かも

from fabric.api import env,sudo,get,run,put,local,execute,hosts
from fabric.decorators import task,hosts
from fabric.context_managers import hide

と指定しておいて

ssh_config ある場合は、

env.use_ssh_config = True
env.host_string= '対象ホスト'
env.user = 'ユーザ名'
env.password = 'パスワード名'

keyfile を指定する場合

env.key_filename='/Users/hoge/.ssh/id' のように指定します。windows でも使えます。#key_filename にしないといけないようです。ubuntu では、env.keyfile でもいけるようです。

それであとは、
x = run('ls -l /srv/www')

などとします。get,put なんかはまだ確認していませんが、多分使えるでしょう。

3
3
0

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
3
3