Migrate ad-hoc feature to use the new ansible become method if provided

This commit is contained in:
Matthew Jones
2015-04-03 15:17:52 -04:00
parent b6e9382273
commit 2e58f5fd00
7 changed files with 628 additions and 20 deletions

View File

@@ -1224,7 +1224,7 @@ class RunAdHocCommand(BaseTask):
ssh-agent for public/private key authentication.
'''
creds = ad_hoc_command.credential
ssh_username, sudo_username, su_username = '', '', ''
ssh_username, become_username, become_method = '', '', ''
if creds:
ssh_username = kwargs.get('username', creds.username)
become_method = kwargs.get('become_method', creds.become_method)
@@ -1258,6 +1258,8 @@ class RunAdHocCommand(BaseTask):
if become_method and become_method == "su" and "become_password" in kwargs.get("passwords", {}):
args.append("--ask-su-pass")
else:
if ad_hoc_command.become_enabled:
args.append('--become')
if become_method:
args.extend(['--become-method', become_method])
if become_username:
@@ -1266,10 +1268,6 @@ class RunAdHocCommand(BaseTask):
args.append('--ask-become-pass')
except ValueError:
pass
if ad_hoc_command.privilege_escalation == 'sudo':
args.append('--sudo')
elif ad_hoc_command.privilege_escalation == 'su':
args.append('--su')
if ad_hoc_command.forks: # FIXME: Max limit?
args.append('--forks=%d' % ad_hoc_command.forks)