Allow sudo_password to be user-configurable

This commit is contained in:
Joseph Hall 2013-11-20 07:53:16 -07:00
parent 10482f4da2
commit 98cda60faa
15 changed files with 61 additions and 21 deletions

View File

@ -280,6 +280,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -356,6 +356,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -1291,6 +1291,9 @@ def create(vm_=None, call=None):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'start_action': __opts__['start_action'],
'parallel': __opts__['parallel'],
'conf_file': __opts__['conf_file'],

View File

@ -191,6 +191,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -317,6 +317,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -466,6 +466,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'start_action': __opts__['start_action'],
'parallel': __opts__['parallel'],
'conf_file': __opts__['conf_file'],

View File

@ -198,6 +198,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -560,6 +560,12 @@ def create(vm_):
'minion_pub': vm_['pub_key'],
'keep_tmp': __opts__['keep_tmp'],
'preseed_minion_keys': vm_.get('preseed_minion_keys', None),
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),
@ -592,13 +598,6 @@ def create(vm_):
log.debug('Logging into SSH using password')
ret = {}
sudo = config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
)
if sudo is not None:
deploy_kwargs['sudo'] = sudo
log.debug('Running root commands using sudo')
if config.get_config_value('deploy', vm_, __opts__) is True:
deploy_script = script(vm_)
deploy_kwargs['script'] = deploy_script.script

View File

@ -653,6 +653,12 @@ def create(vm_):
'minion_pub': vm_['pub_key'],
'keep_tmp': __opts__['keep_tmp'],
'preseed_minion_keys': vm_.get('preseed_minion_keys', None),
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'display_ssh_output': config.get_config_value(
'display_ssh_output', vm_, __opts__, default=True
),
@ -682,13 +688,6 @@ def create(vm_):
log.debug('Logging into SSH using password')
ret = {}
sudo = config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
)
if sudo is not None:
deploy_kwargs['sudo'] = sudo
log.debug('Running root commands using sudo')
if config.get_config_value('deploy', vm_, __opts__) is True:
deploy_script = script(vm_)
deploy_kwargs['script'] = deploy_script.script

View File

@ -367,6 +367,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -361,6 +361,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -110,6 +110,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=True
),

View File

@ -564,6 +564,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -395,6 +395,9 @@ def create(vm_):
'sudo': config.get_config_value(
'sudo', vm_, __opts__, default=(ssh_username != 'root')
),
'sudo_password': config.get_config_value(
'sudo_password', vm_, __opts__, default=None
),
'tty': config.get_config_value(
'tty', vm_, __opts__, default=False
),

View File

@ -500,7 +500,7 @@ def deploy_script(host, port=22, timeout=900, username='root',
keep_tmp=False, script_args=None, script_env=None,
ssh_timeout=15, make_syndic=False, make_minion=True,
display_ssh_output=True, preseed_minion_keys=None,
parallel=False, **kwargs):
parallel=False, sudo_password=None, **kwargs):
'''
Copy a deploy script to a remote server, execute it, and remove it
'''
@ -525,11 +525,14 @@ def deploy_script(host, port=22, timeout=900, username='root',
)
)
newtimeout = timeout - (time.mktime(time.localtime()) - starttime)
kwargs = {'hostname': host,
'port': port,
'username': username,
'timeout': ssh_timeout,
'display_ssh_output': display_ssh_output}
kwargs = {
'hostname': host,
'port': port,
'username': username,
'timeout': ssh_timeout,
'display_ssh_output': display_ssh_output,
'sudo_password': sudo_password,
}
if key_filename:
log.debug('Using {0} as the key_filename'.format(key_filename))
kwargs['key_filename'] = key_filename
@ -947,7 +950,10 @@ def root_cmd(command, tty, sudo, **kwargs):
Wrapper for commands to be run as root
'''
if sudo:
command = 'sudo {0}'.format(command)
if 'sudo_password' in kwargs and kwargs['sudo_password'] is not None:
command = 'echo "{1}" | sudo -S {0}'.format(command, sudo_password)
else:
command = 'sudo {0}'.format(command)
log.debug('Using sudo to run command {0}'.format(command))
ssh_args = []