mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Switch manage.bootstrap to Salt SSH
This commit is contained in:
parent
cd595104bf
commit
70b8574285
@ -12,6 +12,8 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
import uuid
|
||||||
|
|
||||||
# Import 3rd-party libs
|
# Import 3rd-party libs
|
||||||
import salt.ext.six as six
|
import salt.ext.six as six
|
||||||
@ -19,16 +21,18 @@ from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: dis
|
|||||||
|
|
||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt.key
|
import salt.key
|
||||||
import salt.client
|
|
||||||
import salt.utils
|
import salt.utils
|
||||||
import salt.utils.minions
|
import salt.utils.minions
|
||||||
|
import salt.client
|
||||||
|
import salt.client.ssh
|
||||||
import salt.wheel
|
import salt.wheel
|
||||||
import salt.version
|
import salt.version
|
||||||
from salt.utils.event import tagify
|
from salt.utils.event import tagify
|
||||||
from salt.exceptions import SaltClientError
|
from salt.exceptions import SaltClientError, SaltSystemExit
|
||||||
|
|
||||||
FINGERPRINT_REGEX = re.compile(r'^([a-f0-9]{2}:){15}([a-f0-9]{2})$')
|
FINGERPRINT_REGEX = re.compile(r'^([a-f0-9]{2}:){15}([a-f0-9]{2})$')
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def status(output=True):
|
def status(output=True):
|
||||||
'''
|
'''
|
||||||
@ -50,7 +54,6 @@ def status(output=True):
|
|||||||
|
|
||||||
key = salt.key.Key(__opts__)
|
key = salt.key.Key(__opts__)
|
||||||
keys = key.list_keys()
|
keys = key.list_keys()
|
||||||
|
|
||||||
ret['up'] = sorted(minions)
|
ret['up'] = sorted(minions)
|
||||||
ret['down'] = sorted(set(keys['minions']) - set(minions))
|
ret['down'] = sorted(set(keys['minions']) - set(minions))
|
||||||
return ret
|
return ret
|
||||||
@ -127,7 +130,6 @@ def down(removekeys=False):
|
|||||||
wheel.call_func('key.delete', match=minion)
|
wheel.call_func('key.delete', match=minion)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def up(): # pylint: disable=C0103
|
def up(): # pylint: disable=C0103
|
||||||
'''
|
'''
|
||||||
Print a list of all of the minions that are up
|
Print a list of all of the minions that are up
|
||||||
@ -615,7 +617,14 @@ def versions():
|
|||||||
def bootstrap(version='develop',
|
def bootstrap(version='develop',
|
||||||
script=None,
|
script=None,
|
||||||
hosts='',
|
hosts='',
|
||||||
root_user=True):
|
root_user=False,
|
||||||
|
roster='flat',
|
||||||
|
ssh_user='root',
|
||||||
|
ssh_password=None,
|
||||||
|
ssh_priv_key=None,
|
||||||
|
tmp_dir='/tmp/.bootstrap',
|
||||||
|
script_args='',
|
||||||
|
http_backend='tornado'):
|
||||||
'''
|
'''
|
||||||
Bootstrap minions with salt-bootstrap
|
Bootstrap minions with salt-bootstrap
|
||||||
|
|
||||||
@ -637,23 +646,64 @@ def bootstrap(version='develop',
|
|||||||
|
|
||||||
salt-run manage.bootstrap hosts='host1,host2'
|
salt-run manage.bootstrap hosts='host1,host2'
|
||||||
salt-run manage.bootstrap hosts='host1,host2' version='v0.17'
|
salt-run manage.bootstrap hosts='host1,host2' version='v0.17'
|
||||||
salt-run manage.bootstrap hosts='host1,host2' version='v0.17' script='https://bootstrap.saltstack.com/develop'
|
salt-run manage.bootstrap hosts='host1,host2' version='v0.17' \
|
||||||
salt-run manage.bootstrap hosts='ec2-user@host1,ec2-user@host2' root_user=False
|
script='https://bootstrap.saltstack.com/develop'
|
||||||
|
salt-run manage.bootstrap hosts='ec2-user@host1,ec2-user@host2' \
|
||||||
|
root_user=False
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
dep_warning = (
|
||||||
|
'Starting with Salt Carbon, manage.bootstrap now uses Salt SSH to '
|
||||||
|
'connect, and requires a roster entry. Please ensure that a roster '
|
||||||
|
'entry exists for this host. Non-roster hosts will no longer be '
|
||||||
|
'supported starting with Salt Oxygen.'
|
||||||
|
)
|
||||||
|
if root_user is True:
|
||||||
|
salt.utils.warn_until('Oxygen', dep_warning)
|
||||||
|
|
||||||
if script is None:
|
if script is None:
|
||||||
script = 'https://bootstrap.saltstack.com'
|
script = 'https://bootstrap.saltstack.com'
|
||||||
|
|
||||||
for host in hosts.split(','):
|
for host in hosts.split(','):
|
||||||
# Could potentially lean on salt-ssh utils to make
|
client_opts = __opts__.copy()
|
||||||
# deployment easier on existing hosts (i.e. use salt.utils.vt,
|
client_opts['tgt'] = host
|
||||||
# pass better options to ssh, etc)
|
client_opts['selected_target_option'] = 'glob'
|
||||||
subprocess.call(['ssh',
|
tmp_dir = '{0}-{1}/'.format(tmp_dir.rstrip('/'), uuid.uuid4())
|
||||||
('root@' if root_user else '') + host,
|
deploy_command = os.path.join(tmp_dir, 'deploy.sh')
|
||||||
'python -c \'import urllib; '
|
try:
|
||||||
'print urllib.urlopen('
|
client_opts['argv'] = ['file.makedirs', tmp_dir, 'mode=0700']
|
||||||
'\'' + script + '\''
|
salt.client.ssh.SSH(client_opts).run()
|
||||||
').read()\' | sh -s -- git ' + version])
|
client_opts['argv'] = [
|
||||||
|
'http.query',
|
||||||
|
script,
|
||||||
|
'backend={0}'.format(http_backend),
|
||||||
|
'text_out={0}'.format(deploy_command)
|
||||||
|
]
|
||||||
|
client = salt.client.ssh.SSH(client_opts).run()
|
||||||
|
client_opts['argv'] = [
|
||||||
|
'cmd.run',
|
||||||
|
' '.join(['sh', deploy_command, script_args]),
|
||||||
|
'python_shell=False'
|
||||||
|
]
|
||||||
|
salt.client.ssh.SSH(client_opts).run()
|
||||||
|
client_opts['argv'] = ['file.remove', tmp_dir]
|
||||||
|
salt.client.ssh.SSH(client_opts).run()
|
||||||
|
except SaltSystemExit as exc:
|
||||||
|
if 'No hosts found with target' in str(exc):
|
||||||
|
log.warn('The host {0} was not found in the Salt SSH roster '
|
||||||
|
'system. Attempting to log in without Salt SSH.')
|
||||||
|
salt.utils.warn_until('Oxygen', dep_warning)
|
||||||
|
ret = subprocess.call([
|
||||||
|
'ssh',
|
||||||
|
('root@' if root_user else '') + host,
|
||||||
|
'python -c \'import urllib; '
|
||||||
|
'print urllib.urlopen('
|
||||||
|
'\'' + script + '\''
|
||||||
|
').read()\' | sh -s -- git ' + version
|
||||||
|
])
|
||||||
|
return ret
|
||||||
|
else:
|
||||||
|
log.error(str(exc))
|
||||||
|
|
||||||
|
|
||||||
def bootstrap_psexec(hosts='', master=None, version=None, arch='win32',
|
def bootstrap_psexec(hosts='', master=None, version=None, arch='win32',
|
||||||
|
@ -87,8 +87,8 @@ class SaltStackVersion(object):
|
|||||||
'Boron' : (2016, 3),
|
'Boron' : (2016, 3),
|
||||||
'Carbon' : (MAX_SIZE - 103, 0),
|
'Carbon' : (MAX_SIZE - 103, 0),
|
||||||
'Nitrogen' : (MAX_SIZE - 102, 0),
|
'Nitrogen' : (MAX_SIZE - 102, 0),
|
||||||
|
'Oxygen' : (MAX_SIZE - 101, 0),
|
||||||
# pylint: disable=E8265
|
# pylint: disable=E8265
|
||||||
#'Oxygen' : (MAX_SIZE - 101, 0),
|
|
||||||
#'Fluorine' : (MAX_SIZE - 100, 0),
|
#'Fluorine' : (MAX_SIZE - 100, 0),
|
||||||
#'Neon' : (MAX_SIZE - 99 , 0),
|
#'Neon' : (MAX_SIZE - 99 , 0),
|
||||||
#'Sodium' : (MAX_SIZE - 98 , 0),
|
#'Sodium' : (MAX_SIZE - 98 , 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user