Move _split_args from ssh.py to ConnectionBase so we can use it in other connection plugins
This commit is contained in:
parent
630a35adb0
commit
a8e0763d1e
2 changed files with 13 additions and 12 deletions
|
@ -23,6 +23,7 @@ __metaclass__ = type
|
||||||
import fcntl
|
import fcntl
|
||||||
import gettext
|
import gettext
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
from abc import ABCMeta, abstractmethod, abstractproperty
|
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
@ -31,6 +32,7 @@ from ansible.compat.six import with_metaclass
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins import shell_loader
|
from ansible.plugins import shell_loader
|
||||||
|
from ansible.utils.unicode import to_bytes, to_unicode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -112,6 +114,15 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
|
||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _split_ssh_args(argstring):
|
||||||
|
"""
|
||||||
|
Takes a string like '-o Foo=1 -o Bar="foo bar"' and returns a
|
||||||
|
list ['-o', 'Foo=1', '-o', 'Bar=foo bar'] that can be added to
|
||||||
|
the argument list. The list will not contain any empty elements.
|
||||||
|
"""
|
||||||
|
return [to_unicode(x.strip()) for x in shlex.split(to_bytes(argstring)) if x.strip()]
|
||||||
|
|
||||||
@abstractproperty
|
@abstractproperty
|
||||||
def transport(self):
|
def transport(self):
|
||||||
"""String used to identify this Connection class from other classes"""
|
"""String used to identify this Connection class from other classes"""
|
||||||
|
|
|
@ -24,7 +24,6 @@ import os
|
||||||
import pipes
|
import pipes
|
||||||
import pty
|
import pty
|
||||||
import select
|
import select
|
||||||
import shlex
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -100,15 +99,6 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
return controlpersist, controlpath
|
return controlpersist, controlpath
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _split_args(argstring):
|
|
||||||
"""
|
|
||||||
Takes a string like '-o Foo=1 -o Bar="foo bar"' and returns a
|
|
||||||
list ['-o', 'Foo=1', '-o', 'Bar=foo bar'] that can be added to
|
|
||||||
the argument list. The list will not contain any empty elements.
|
|
||||||
"""
|
|
||||||
return [to_unicode(x.strip()) for x in shlex.split(to_bytes(argstring)) if x.strip()]
|
|
||||||
|
|
||||||
def _add_args(self, explanation, args):
|
def _add_args(self, explanation, args):
|
||||||
"""
|
"""
|
||||||
Adds the given args to self._command and displays a caller-supplied
|
Adds the given args to self._command and displays a caller-supplied
|
||||||
|
@ -157,7 +147,7 @@ class Connection(ConnectionBase):
|
||||||
# Next, we add [ssh_connection]ssh_args from ansible.cfg.
|
# Next, we add [ssh_connection]ssh_args from ansible.cfg.
|
||||||
|
|
||||||
if self._play_context.ssh_args:
|
if self._play_context.ssh_args:
|
||||||
args = self._split_args(self._play_context.ssh_args)
|
args = self._split_ssh_args(self._play_context.ssh_args)
|
||||||
self._add_args("ansible.cfg set ssh_args", args)
|
self._add_args("ansible.cfg set ssh_args", args)
|
||||||
|
|
||||||
# Now we add various arguments controlled by configuration file settings
|
# Now we add various arguments controlled by configuration file settings
|
||||||
|
@ -210,7 +200,7 @@ class Connection(ConnectionBase):
|
||||||
for opt in ['ssh_common_args', binary + '_extra_args']:
|
for opt in ['ssh_common_args', binary + '_extra_args']:
|
||||||
attr = getattr(self._play_context, opt, None)
|
attr = getattr(self._play_context, opt, None)
|
||||||
if attr is not None:
|
if attr is not None:
|
||||||
args = self._split_args(attr)
|
args = self._split_ssh_args(attr)
|
||||||
self._add_args("PlayContext set %s" % opt, args)
|
self._add_args("PlayContext set %s" % opt, args)
|
||||||
|
|
||||||
# Check if ControlPersist is enabled and add a ControlPath if one hasn't
|
# Check if ControlPersist is enabled and add a ControlPath if one hasn't
|
||||||
|
|
Loading…
Reference in a new issue