Merge pull request #49466 from rallytime/bp-49461

Back-port #49461 to 2017.7.8
This commit is contained in:
Nicole Thomas 2018-08-31 11:44:10 -04:00 committed by GitHub
commit 52ab2c0574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 61 deletions

View file

@ -341,12 +341,12 @@ class SSH(object):
'''
Deploy the SSH key if the minions don't auth
'''
if not isinstance(ret[host], dict) or self.opts.get('ssh_key_deploy') is True:
if not isinstance(ret[host], dict) or self.opts.get('ssh_key_deploy'):
target = self.targets[host]
if target.get('passwd', False) or self.opts['ssh_passwd']:
self._key_deploy_run(host, target, False)
return ret
if ret[host].get('stderr', '').count('Permission denied') and not self.opts.get('ssh_key_deploy') is False:
if ret[host].get('stderr', '').count('Permission denied'):
target = self.targets[host]
# permission denied, attempt to auto deploy ssh key
print(('Permission denied for host {0}, do you want to deploy '

View file

@ -3014,21 +3014,12 @@ class SaltSSHOptionParser(six.with_metaclass(OptionParserMeta,
auth_group.add_option(
'--key-deploy',
dest='ssh_key_deploy',
default=None,
default=False,
action='store_true',
help='Set this flag to attempt to deploy the authorized ssh key '
'with all minions. This combined with --passwd can make '
'initial deployment of keys very fast and easy.'
)
auth_group.add_option(
'--no-key-deploy',
dest='ssh_key_deploy',
default=None,
action='store_false',
help='Set this flag to stop salt-ssh from attempting to deploy an authorized ssh key '
'with all minions. This is useful to skip the message about deploying to minions '
'that cannot be logged into.'
)
auth_group.add_option(
'--identities-only',
dest='ssh_identities_only',

View file

@ -1,49 +0,0 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Daniel Wallace (daniel@saltstack.com)`
====================================
Test Case for --no-key-deploy
====================================
'''
from __future__ import unicode_literals, absolute_import
# Import Python Libs
import os
import json
# Import Tests Libs
from tests.support.case import SSHCase
from tests.support.runtests import RUNTIME_VARS
class SSHKeyDeployQuestionCase(SSHCase):
def _run_ssh(self, arg_str, with_retcode=False, timeout=25, catch_stderr=False):
arg_str = '-ldebug -c {0} -i --roster-file {1} --out=json localhost {2}'.format(
self.get_config_dir(),
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, '_ssh', 'roster'),
arg_str,
)
return self.run_script('salt-ssh',
arg_str,
with_retcode=with_retcode,
catch_stderr=catch_stderr,
timeout=timeout,
raw=True)
def test_no_key_deploy(self):
exp = {
'localhost': {
'stdout': '',
'stderr': "Permission denied (publickey).\r\n",
'retcode': 255,
},
}
assert json.loads(self._run_ssh('--no-key-deploy localhost test.ping')) == exp
def test_key_deploy(self):
exp = ['Process took more than 5 seconds to complete. Process Killed!']
assert self._run_ssh('localhost test.ping', timeout=5) == exp