Merge pull request #387 from skvidal/devel
implement --private-key for ansible - to take pem files as an optional arg
This commit is contained in:
commit
306bab93d8
7 changed files with 17 additions and 5 deletions
|
@ -91,6 +91,7 @@ class Cli(object):
|
||||||
module_args=options.module_args,
|
module_args=options.module_args,
|
||||||
remote_user=options.remote_user, remote_pass=sshpass,
|
remote_user=options.remote_user, remote_pass=sshpass,
|
||||||
inventory=inventory_manager, timeout=options.timeout,
|
inventory=inventory_manager, timeout=options.timeout,
|
||||||
|
private_key_file=options.private_key_file,
|
||||||
forks=options.forks,
|
forks=options.forks,
|
||||||
pattern=pattern,
|
pattern=pattern,
|
||||||
callbacks=self.callbacks, sudo=options.sudo,
|
callbacks=self.callbacks, sudo=options.sudo,
|
||||||
|
|
|
@ -77,7 +77,8 @@ def main(args):
|
||||||
sudo=options.sudo,
|
sudo=options.sudo,
|
||||||
sudo_user=options.sudo_user,
|
sudo_user=options.sudo_user,
|
||||||
sudo_pass=sudopass,
|
sudo_pass=sudopass,
|
||||||
extra_vars=extra_vars
|
extra_vars=extra_vars,
|
||||||
|
private_key_file=options.private_key_file
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,8 @@ class ParamikoConnection(object):
|
||||||
username=user,
|
username=user,
|
||||||
allow_agent=True,
|
allow_agent=True,
|
||||||
look_for_keys=True,
|
look_for_keys=True,
|
||||||
|
key_filename=self.runner.private_key_file,
|
||||||
password=self.runner.remote_pass,
|
password=self.runner.remote_pass,
|
||||||
# key_filename=None, # TODO: allow this to be passed in
|
|
||||||
timeout=self.runner.timeout,
|
timeout=self.runner.timeout,
|
||||||
port=self.port
|
port=self.port
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,6 +34,7 @@ DEFAULT_TIMEOUT = 10
|
||||||
DEFAULT_POLL_INTERVAL = 15
|
DEFAULT_POLL_INTERVAL = 15
|
||||||
DEFAULT_REMOTE_USER = 'root'
|
DEFAULT_REMOTE_USER = 'root'
|
||||||
DEFAULT_REMOTE_PASS = None
|
DEFAULT_REMOTE_PASS = None
|
||||||
|
DEFAULT_PRIVATE_KEY_FILE = None
|
||||||
DEFAULT_SUDO_PASS = None
|
DEFAULT_SUDO_PASS = None
|
||||||
DEFAULT_SUDO_USER = 'root'
|
DEFAULT_SUDO_USER = 'root'
|
||||||
DEFAULT_REMOTE_PORT = 22
|
DEFAULT_REMOTE_PORT = 22
|
||||||
|
|
|
@ -56,6 +56,7 @@ class PlayBook(object):
|
||||||
sudo_pass = C.DEFAULT_SUDO_PASS,
|
sudo_pass = C.DEFAULT_SUDO_PASS,
|
||||||
remote_port = C.DEFAULT_REMOTE_PORT,
|
remote_port = C.DEFAULT_REMOTE_PORT,
|
||||||
transport = C.DEFAULT_TRANSPORT,
|
transport = C.DEFAULT_TRANSPORT,
|
||||||
|
private_key_file = C.DEFAULT_PRIVATE_KEY_FILE,
|
||||||
debug = False,
|
debug = False,
|
||||||
callbacks = None,
|
callbacks = None,
|
||||||
runner_callbacks = None,
|
runner_callbacks = None,
|
||||||
|
@ -103,6 +104,7 @@ class PlayBook(object):
|
||||||
self.sudo_user = sudo_user
|
self.sudo_user = sudo_user
|
||||||
self.extra_vars = extra_vars
|
self.extra_vars = extra_vars
|
||||||
self.global_vars = {}
|
self.global_vars = {}
|
||||||
|
self.private_key_file = private_key_file
|
||||||
|
|
||||||
self.inventory = ansible.inventory.Inventory(host_list)
|
self.inventory = ansible.inventory.Inventory(host_list)
|
||||||
|
|
||||||
|
@ -283,6 +285,7 @@ class PlayBook(object):
|
||||||
remote_pass=self.remote_pass, module_path=self.module_path,
|
remote_pass=self.remote_pass, module_path=self.module_path,
|
||||||
timeout=self.timeout, remote_user=remote_user,
|
timeout=self.timeout, remote_user=remote_user,
|
||||||
remote_port=port, module_vars=vars,
|
remote_port=port, module_vars=vars,
|
||||||
|
private_key_file=self.private_key_file,
|
||||||
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
||||||
conditional=only_if, callbacks=self.runner_callbacks,
|
conditional=only_if, callbacks=self.runner_callbacks,
|
||||||
debug=self.debug, sudo=sudo, sudo_user=sudo_user,
|
debug=self.debug, sudo=sudo, sudo_user=sudo_user,
|
||||||
|
@ -474,6 +477,7 @@ class PlayBook(object):
|
||||||
forks=self.forks, module_path=self.module_path,
|
forks=self.forks, module_path=self.module_path,
|
||||||
timeout=self.timeout, remote_user=user,
|
timeout=self.timeout, remote_user=user,
|
||||||
remote_pass=self.remote_pass, remote_port=port,
|
remote_pass=self.remote_pass, remote_port=port,
|
||||||
|
private_key_file=self.private_key_file,
|
||||||
setup_cache=SETUP_CACHE,
|
setup_cache=SETUP_CACHE,
|
||||||
callbacks=self.runner_callbacks, sudo=sudo, sudo_user=sudo_user,
|
callbacks=self.runner_callbacks, sudo=sudo, sudo_user=sudo_user,
|
||||||
debug=self.debug, transport=transport,
|
debug=self.debug, transport=transport,
|
||||||
|
|
|
@ -76,9 +76,10 @@ class Runner(object):
|
||||||
forks=C.DEFAULT_FORKS, timeout=C.DEFAULT_TIMEOUT,
|
forks=C.DEFAULT_FORKS, timeout=C.DEFAULT_TIMEOUT,
|
||||||
pattern=C.DEFAULT_PATTERN, remote_user=C.DEFAULT_REMOTE_USER,
|
pattern=C.DEFAULT_PATTERN, remote_user=C.DEFAULT_REMOTE_USER,
|
||||||
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,
|
private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, sudo_pass=C.DEFAULT_SUDO_PASS,
|
||||||
setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True',
|
background=0, basedir=None, setup_cache=None,
|
||||||
callbacks=None, debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER,
|
transport=C.DEFAULT_TRANSPORT, conditional='True', callbacks=None,
|
||||||
|
debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER,
|
||||||
module_vars=None, is_playbook=False, inventory=None):
|
module_vars=None, is_playbook=False, inventory=None):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -92,6 +93,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)
|
||||||
|
private_key_file : use this private key as your auth key
|
||||||
sudo_user : If you want to sudo to a user other than root.
|
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)
|
||||||
|
@ -142,6 +144,7 @@ class Runner(object):
|
||||||
self.remote_user = remote_user
|
self.remote_user = remote_user
|
||||||
self.remote_pass = remote_pass
|
self.remote_pass = remote_pass
|
||||||
self.remote_port = remote_port
|
self.remote_port = remote_port
|
||||||
|
self.private_key_file = private_key_file
|
||||||
self.background = background
|
self.background = background
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
self.sudo = sudo
|
self.sudo = sudo
|
||||||
|
|
|
@ -318,6 +318,8 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, asyn
|
||||||
default=constants.DEFAULT_HOST_LIST)
|
default=constants.DEFAULT_HOST_LIST)
|
||||||
parser.add_option('-k', '--ask-pass', default=False, dest='ask_pass', action='store_true',
|
parser.add_option('-k', '--ask-pass', default=False, dest='ask_pass', action='store_true',
|
||||||
help='ask for SSH password')
|
help='ask for SSH password')
|
||||||
|
parser.add_option('--private-key', default=None, dest='private_key_file',
|
||||||
|
help='use this file to authenticate the connection')
|
||||||
parser.add_option('-K', '--ask-sudo-pass', default=False, dest='ask_sudo_pass', action='store_true',
|
parser.add_option('-K', '--ask-sudo-pass', default=False, dest='ask_sudo_pass', action='store_true',
|
||||||
help='ask for sudo password')
|
help='ask for sudo password')
|
||||||
parser.add_option('-M', '--module-path', dest='module_path',
|
parser.add_option('-M', '--module-path', dest='module_path',
|
||||||
|
|
Loading…
Reference in a new issue