diff --git a/examples/ansible.cfg b/examples/ansible.cfg index a07f7149c18..c309fc41c9d 100644 --- a/examples/ansible.cfg +++ b/examples/ansible.cfg @@ -66,3 +66,16 @@ remote_port=22 #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 + + diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 17c498258b1..7c6195d8964 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -82,3 +82,4 @@ DEFAULT_TRANSPORT_OPTS = ['local', 'paramiko', 'ssh'] DEFAULT_SUDO_PASS = None DEFAULT_SUBSET = None +ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None) diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index a813611ca6e..85dce9d8eac 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -23,6 +23,7 @@ import pipes import random import select import fcntl +import ansible.constants as C from ansible.callbacks import vvv from ansible import errors @@ -40,7 +41,7 @@ class SSHConnection(object): vvv("ESTABLISH CONNECTION FOR USER: %s" % self.runner.remote_user, host=self.host) self.common_args = [] - extra_args = os.getenv("ANSIBLE_SSH_ARGS", None) + extra_args = C.ANSIBLE_SSH_ARGS if extra_args is not None: self.common_args += shlex.split(extra_args) else: @@ -108,7 +109,7 @@ class SSHConnection(object): 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: - 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, '')