elssar
elssar

Reputation: 5871

Fabric not using the correct key

In my fabfile, I have set env.use_ssh_config to True. Whenever I run the fabfile, it will get the correct hostname and user from the ssh config, but not the correct key. It will go though my keys(all stored in ~/.ssh/) at random, requiring me to enter the passphrase for all of them, till it gets to the correct key.

It's only fabric that gives me this problem. Running scp as a local command in the fabfile uses the correct key.

Host example
    HostName example.com
    User elssar
    IdentityFile ~/.ssh/id_example
    PreferredAuthentications publickey

Entries in my ssh config look like this.

I'm, using Fabric 1.10.1 and Paramiko 1.14.1, Python 2.7.3 and Ubuntu 12.04.

Edit - There is a related open issue in the fabric repository - https://github.com/fabric/fabric/issues/1282

Edit - basic structure of my fabfile, and how I run it

from fabric.api import env, run

def do_something():
    run("echo test")

def setup(host):
    env.hosts = [host]


# command
fab server:hostname do_something

Upvotes: 2

Views: 1133

Answers (1)

dnozay
dnozay

Reputation: 24324

I tried to check on my setup; here is what I did to debug:

>>> from fabric.network import key_filenames
>>> key_filenames()
[]
>>> from fabric.state import env
>>> env.use_ssh_config = True
>>> env.host_string = 'salt-states'
>>> key_filenames()
['/Users/damien/.ssh/salt.rsa.priv']

update: you could update your fabfile to instrument your task:

from fabric.api import env, run
from fabric.network import key_filenames

def do_something_debug():
    env.use_ssh_config = True
    print key_filenames()
    run("echo test")

def server(host):
    env.hosts = [host]

then run the command

fab server:hostname do_something_debug

Upvotes: 1

Related Questions