LoginSignup
1
2

More than 5 years have passed since last update.

Fabric 2 で接続周りをシンプルにしたい

Posted at

Fabric 2 で env を fabric みたいに何も考えずに設定して接続というのをやろうとしてたんだけど下記のように出来なさそう。
global は、バッドノウハウな匂いしかしないんだけど、他にやる方法ないのかな。
おとなしく .ssh/config を設定してそれを読み込ませるようにするのがベターなのかしら?

# -*- coding:utf-8 -*-
from fabric import Connection
from invoke import task

env = {}
conn = None


@task
def env_vagrant(c):
    global conn
    env['host'] = 'localhost'
    env['user'] = 'vagrant'
    env['kwargs'] = {
        'key_filename': '/home/vagrant/.ssh/id_rsa',
    }
    conn = Connection(
        env['host'],
        user=env['user'],
        connect_kwargs=env['kwargs'])


@task
def info(c):
    conn.run('pwd')
    conn.run('python --version')
    conn.run('pipenv --version')
    conn.local('ls')
1
2
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
1
2