Adding ability to set ssh args from config file

This commit is contained in:
Michael DeHaan 2012-08-14 20:13:02 -04:00
parent 6de8c27085
commit 9851066f4d
3 changed files with 17 additions and 2 deletions

View file

@ -66,3 +66,16 @@ remote_port=22
#private_key_file=/path/to/file #private_key_file=/path/to/file
[paramiko_connection]
# nothing to configure yet
[ssh_connection]
# if uncommented, sets the ansible ssh arguments to the following. Leaving off ControlPersist
# will result in poor performance, so use transport=paramiko on older platforms rather than
# removing it
ssh_args=-o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r

View file

@ -82,3 +82,4 @@ DEFAULT_TRANSPORT_OPTS = ['local', 'paramiko', 'ssh']
DEFAULT_SUDO_PASS = None DEFAULT_SUDO_PASS = None
DEFAULT_SUBSET = None DEFAULT_SUBSET = None
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None)

View file

@ -23,6 +23,7 @@ import pipes
import random import random
import select import select
import fcntl import fcntl
import ansible.constants as C
from ansible.callbacks import vvv from ansible.callbacks import vvv
from ansible import errors from ansible import errors
@ -40,7 +41,7 @@ class SSHConnection(object):
vvv("ESTABLISH CONNECTION FOR USER: %s" % self.runner.remote_user, host=self.host) vvv("ESTABLISH CONNECTION FOR USER: %s" % self.runner.remote_user, host=self.host)
self.common_args = [] self.common_args = []
extra_args = os.getenv("ANSIBLE_SSH_ARGS", None) extra_args = C.ANSIBLE_SSH_ARGS
if extra_args is not None: if extra_args is not None:
self.common_args += shlex.split(extra_args) self.common_args += shlex.split(extra_args)
else: else:
@ -108,7 +109,7 @@ class SSHConnection(object):
p.stdin.close() # close stdin after we read from stdout (see also issue #848) p.stdin.close() # close stdin after we read from stdout (see also issue #848)
if p.returncode != 0 and stdout.find('Bad configuration option: ControlPersist') != -1: if p.returncode != 0 and stdout.find('Bad configuration option: ControlPersist') != -1:
raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again') raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ssh_args in the config file) before running again')
return ('', stdout, '') return ('', stdout, '')