I don't know why this was ever the case, but ignoring user@host
from the targets list just seems like a bad idea, and causes
problems, because tasks/ansible/etc. assume that the user to use
is ubuntu. If that's not what .ssh/config says, there's just
going to be trouble...but there's no reason to pay attention
to .ssh/config there; if you really want to play tricks, edit
your target list accordingly.
Also, the original code was apparently not prepared for the
key_filename to be a list, which it apparently always is,
at least now; handle that too.
Fixes: http://tracker.ceph.com/issues/17125
Signed-off-by: Dan Mick <dan.mick@redhat.com>
username=user,
timeout=timeout
)
- if key_filename:
- connect_args['key_filename'] = key_filename
ssh_config_path = os.path.expanduser("~/.ssh/config")
if os.path.exists(ssh_config_path):
ssh_config = paramiko.SSHConfig()
ssh_config.parse(open(ssh_config_path))
opts = ssh_config.lookup(host)
- opts_to_args = {
- 'host': 'hostname',
- 'user': 'username'
- }
- if not key_filename:
- opts_to_args['identityfile'] = 'key_filename'
- for opt_name, arg_name in opts_to_args.items():
- if opt_name in opts:
- value = opts[opt_name]
- if arg_name == 'key_filename' and '~' in value:
- value = os.path.expanduser(value)
- connect_args[arg_name] = value
+ if not key_filename and 'identityfile' in opts:
+ key_filename = opts['identityfile']
+
+ if key_filename:
+ key_filename = [os.path.expanduser(f) for f in key_filename]
+ connect_args['key_filename'] = key_filename
log.debug(connect_args)