first bit of getting sudo -u functionality

pull/603/head
Jim Richardson 13 years ago committed by Michael DeHaan
parent 36559badd5
commit 93a20a33e9

@ -52,7 +52,8 @@ class Cli(object):
parser.add_option('-m', '--module-name', dest='module_name', parser.add_option('-m', '--module-name', dest='module_name',
help="module name to execute (default=%s)" % C.DEFAULT_MODULE_NAME, help="module name to execute (default=%s)" % C.DEFAULT_MODULE_NAME,
default=C.DEFAULT_MODULE_NAME) default=C.DEFAULT_MODULE_NAME)
parser.add_option('-U','--sudo_user', dest='sudo_user', help='desired sudo user',
default=C.DEFAULT_SUDO_USER)
options, args = parser.parse_args() options, args = parser.parse_args()
self.callbacks.options = options self.callbacks.options = options
@ -76,6 +77,7 @@ class Cli(object):
sshpass = None sshpass = None
sudopass = None sudopass = None
sudouser = options.sudo_user
if options.ask_pass: if options.ask_pass:
sshpass = getpass.getpass(prompt="SSH password: ") sshpass = getpass.getpass(prompt="SSH password: ")
if options.ask_sudo_pass: if options.ask_sudo_pass:
@ -92,7 +94,7 @@ class Cli(object):
forks=options.forks, forks=options.forks,
pattern=pattern, pattern=pattern,
callbacks=self.callbacks, sudo=options.sudo, callbacks=self.callbacks, sudo=options.sudo,
sudo_pass=sudopass, sudo_pass=sudopass,sudo_user=options.sudo_user,
transport=options.connection, debug=options.debug transport=options.connection, debug=options.debug
) )

@ -33,6 +33,7 @@ DEFAULT_POLL_INTERVAL = 15
DEFAULT_REMOTE_USER = 'root' DEFAULT_REMOTE_USER = 'root'
DEFAULT_REMOTE_PASS = None DEFAULT_REMOTE_PASS = None
DEFAULT_SUDO_PASS = None DEFAULT_SUDO_PASS = None
DEFAULT_SUDO_USER = 'root'
DEFAULT_REMOTE_PORT = 22 DEFAULT_REMOTE_PORT = 22
DEFAULT_TRANSPORT = 'paramiko' DEFAULT_TRANSPORT = 'paramiko'
DEFAULT_TRANSPORT_OPTS = ['local', 'paramiko'] DEFAULT_TRANSPORT_OPTS = ['local', 'paramiko']

@ -77,8 +77,8 @@ class Runner(object):
remote_pass=C.DEFAULT_REMOTE_PASS, remote_port=C.DEFAULT_REMOTE_PORT, remote_pass=C.DEFAULT_REMOTE_PASS, remote_port=C.DEFAULT_REMOTE_PORT,
sudo_pass=C.DEFAULT_SUDO_PASS, background=0, basedir=None, sudo_pass=C.DEFAULT_SUDO_PASS, background=0, basedir=None,
setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True', setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True',
callbacks=None, debug=False, sudo=False, module_vars=None, callbacks=None, debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER
is_playbook=False, inventory=None): ,module_vars=None, is_playbook=False, inventory=None):
""" """
host_list : path to a host list file, like /etc/ansible/hosts host_list : path to a host list file, like /etc/ansible/hosts
@ -91,6 +91,7 @@ class Runner(object):
remote_user : connect as this remote username remote_user : connect as this remote username
remote_pass : supply this password (if not using keys) remote_pass : supply this password (if not using keys)
remote_port : use this default remote port (if not set by the inventory system) remote_port : use this default remote port (if not set by the inventory system)
sudo_user : If you want to sudo to a user other than root.
sudo_pass : sudo password if using sudo and sudo requires a password sudo_pass : sudo password if using sudo and sudo requires a password
background : run asynchronously with a cap of this many # of seconds (if not 0) background : run asynchronously with a cap of this many # of seconds (if not 0)
basedir : paths used by modules if not absolute are relative to here basedir : paths used by modules if not absolute are relative to here
@ -143,6 +144,7 @@ class Runner(object):
self.basedir = basedir self.basedir = basedir
self.sudo = sudo self.sudo = sudo
self.sudo_pass = sudo_pass self.sudo_pass = sudo_pass
self.sudo_user = sudo_user
self.is_playbook = is_playbook self.is_playbook = is_playbook
euid = pwd.getpwuid(os.geteuid())[0] euid = pwd.getpwuid(os.geteuid())[0]

Loading…
Cancel
Save