Allow overriding ansible_ssh_extra_args on the command-line

This patch makes it possible to do:

    ansible somehost -m setup \
        --ssh-extra-args '-o ProxyCommand="ssh -W %h:%p -q user@bouncer.example.com"'

This overrides the inventory setting, if any, of ansible_ssh_extra_args.

Based on a patch originally by @Richard2ndQuadrant.
This commit is contained in:
Abhijit Menon-Sen 2015-08-10 19:42:30 +05:30
parent b023ace8a8
commit 37c1a5b679
3 changed files with 8 additions and 3 deletions

View file

@ -315,6 +315,8 @@ class CLI(object):
help="connection type to use (default=%s)" % C.DEFAULT_TRANSPORT)
parser.add_option('-T', '--timeout', default=C.DEFAULT_TIMEOUT, type='int', dest='timeout',
help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT)
parser.add_option('--ssh-extra-args', default='', dest='ssh_extra_args',
help="specify extra arguments to pass to ssh (e.g. ProxyCommand)")
if async_opts:
parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', dest='poll_interval',

View file

@ -163,6 +163,7 @@ class PlayContext(Base):
_private_key_file = FieldAttribute(isa='string', default=C.DEFAULT_PRIVATE_KEY_FILE)
_timeout = FieldAttribute(isa='int', default=C.DEFAULT_TIMEOUT)
_shell = FieldAttribute(isa='string')
_ssh_extra_args = FieldAttribute(isa='string')
_connection_lockfd= FieldAttribute(isa='int')
# privilege escalation fields
@ -252,6 +253,7 @@ class PlayContext(Base):
self.remote_user = options.remote_user
self.private_key_file = options.private_key_file
self.ssh_extra_args = options.ssh_extra_args
# privilege escalation
self.become = options.become

View file

@ -121,9 +121,10 @@ class Connection(ConnectionBase):
self._common_args += ("-o", "ConnectTimeout={0}".format(self._play_context.timeout))
# If any extra SSH arguments are specified in the inventory for
# this host, add them in.
if self.ssh_extra_args is not None:
extra_args = self.ssh_extra_args
# this host, or specified as an override on the command line,
# add them in.
extra_args = self._play_context.ssh_extra_args or self.ssh_extra_args
if extra_args is not None:
self._common_args += [x.strip() for x in shlex.split(extra_args) if x.strip()]
self._connected = True