Skip to content
Browse files

Adding ability to set ssh args from config file

  • Loading branch information...
1 parent 6de8c27 commit 9851066f4de0ca48bbe3927ef333778f9df1db98 @mpdehaan mpdehaan committed
Showing with 17 additions and 2 deletions.
  1. +13 −0 examples/ansible.cfg
  2. +1 −0 lib/ansible/constants.py
  3. +3 −2 lib/ansible/runner/connection/ssh.py
View
13 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
+
+
View
1 lib/ansible/constants.py
@@ -82,3 +82,4 @@ def shell_expand_path(path):
DEFAULT_SUDO_PASS = None
DEFAULT_SUBSET = None
+ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None)
View
5 lib/ansible/runner/connection/ssh.py
@@ -23,6 +23,7 @@
import random
import select
import fcntl
+import ansible.constants as C
from ansible.callbacks import vvv
from ansible import errors
@@ -40,7 +41,7 @@ def connect(self):
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 @@ def exec_command(self, cmd, tmp_path, sudo_user,sudoable=False):
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, '')

0 comments on commit 9851066

Please sign in to comment.
Something went wrong with that request. Please try again.