summaryrefslogtreecommitdiffstats
path: root/lib/ansible/plugins/connection
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/connection')
-rw-r--r--lib/ansible/plugins/connection/__init__.py9
-rw-r--r--lib/ansible/plugins/connection/local.py7
-rw-r--r--lib/ansible/plugins/connection/paramiko_ssh.py3
-rw-r--r--lib/ansible/plugins/connection/psrp.py5
-rw-r--r--lib/ansible/plugins/connection/ssh.py72
-rw-r--r--lib/ansible/plugins/connection/winrm.py7
6 files changed, 31 insertions, 72 deletions
diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py
index 5f7e282..e769770 100644
--- a/lib/ansible/plugins/connection/__init__.py
+++ b/lib/ansible/plugins/connection/__init__.py
@@ -2,8 +2,7 @@
# (c) 2015 Toshio Kuratomi <tkuratomi@ansible.com>
# (c) 2017, Peter Sprygada <psprygad@redhat.com>
# (c) 2017 Ansible Project
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import collections.abc as c
import fcntl
@@ -267,19 +266,19 @@ class ConnectionBase(AnsiblePlugin):
# its my cousin ...
value = self._shell._load_name
else:
- # deal with generic options if the plugin supports em (for exmaple not all connections have a remote user)
+ # deal with generic options if the plugin supports em (for example not all connections have a remote user)
options = C.config.get_plugin_options_from_var('connection', self._load_name, varname)
if options:
value = self.get_option(options[0]) # for these variables there should be only one option
elif 'become' not in varname:
- # fallback to play_context, unles becoem related TODO: in the end should come from task/play and not pc
+ # fallback to play_context, unless become related TODO: in the end, should come from task/play and not pc
for prop, var_list in C.MAGIC_VARIABLE_MAPPING.items():
if varname in var_list:
try:
value = getattr(self._play_context, prop)
break
except AttributeError:
- # it was not defined, fine to ignore
+ # It was not defined; fine to ignore
continue
if value is not None:
diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py
index d6dccc7..464d8e8 100644
--- a/lib/ansible/plugins/connection/local.py
+++ b/lib/ansible/plugins/connection/local.py
@@ -2,8 +2,7 @@
# (c) 2015, 2017 Toshio Kuratomi <tkuratomi@ansible.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = '''
name: local
@@ -22,13 +21,13 @@ import fcntl
import getpass
import os
import pty
+import selectors
import shutil
import subprocess
import typing as t
import ansible.constants as C
from ansible.errors import AnsibleError, AnsibleFileNotFound
-from ansible.module_utils.compat import selectors
from ansible.module_utils.six import text_type, binary_type
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase
@@ -90,7 +89,7 @@ class Connection(ConnectionBase):
master = None
stdin = subprocess.PIPE
if sudoable and self.become and self.become.expect_prompt() and not self.get_option('pipelining'):
- # Create a pty if sudoable for privlege escalation that needs it.
+ # Create a pty if sudoable for privilege escalation that needs it.
# Falls back to using a standard pipe if this fails, which may
# cause the command to fail in certain situations where we are escalating
# privileges or the command otherwise needs a pty.
diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py
index 172dbda..924208b 100644
--- a/lib/ansible/plugins/connection/paramiko_ssh.py
+++ b/lib/ansible/plugins/connection/paramiko_ssh.py
@@ -1,8 +1,7 @@
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
author: Ansible Core Team
diff --git a/lib/ansible/plugins/connection/psrp.py b/lib/ansible/plugins/connection/psrp.py
index 37a4694..b69a1d8 100644
--- a/lib/ansible/plugins/connection/psrp.py
+++ b/lib/ansible/plugins/connection/psrp.py
@@ -1,8 +1,7 @@
# Copyright (c) 2018 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
author: Ansible Core Team
@@ -14,7 +13,7 @@ description:
underlying transport but instead runs in a PowerShell interpreter.
version_added: "2.7"
requirements:
-- pypsrp>=0.4.0 (Python library)
+- pypsrp>=0.4.0, <1.0.0 (Python library)
extends_documentation_fragment:
- connection_pipelining
options:
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py
index 49b2ed2..5c4c28d 100644
--- a/lib/ansible/plugins/connection/ssh.py
+++ b/lib/ansible/plugins/connection/ssh.py
@@ -4,8 +4,7 @@
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = '''
name: ssh
@@ -20,6 +19,8 @@ DOCUMENTATION = '''
- connection_pipelining
version_added: historical
notes:
+ - This plugin is mostly a wrapper to the ``ssh`` CLI utility and the exact behavior of the options depends on this tool.
+ This means that the documentation provided here is subject to be overridden by the CLI tool itself.
- Many options default to V(None) here but that only means we do not override the SSH tool's defaults and/or configuration.
For example, if you specify the port in this plugin it will override any C(Port) entry in your C(.ssh/config).
- The ssh CLI tool uses return code 255 as a 'connection error', this can conflict with commands/tools that
@@ -36,7 +37,7 @@ DOCUMENTATION = '''
- name: delegated_vars['ansible_host']
- name: delegated_vars['ansible_ssh_host']
host_key_checking:
- description: Determines if SSH should check host keys.
+ description: Determines if SSH should reject or not a connection after checking host keys.
default: True
type: boolean
ini:
@@ -304,12 +305,13 @@ DOCUMENTATION = '''
- name: ansible_sftp_batch_mode
version_added: '2.7'
ssh_transfer_method:
- description:
- - "Preferred method to use when transferring files over ssh"
- - Setting to 'smart' (default) will try them in order, until one succeeds or they all fail
- - For OpenSSH >=9.0 you must add an additional option to enable scp (scp_extra_args="-O")
- - Using 'piped' creates an ssh pipe with C(dd) on either side to copy the data
- choices: ['sftp', 'scp', 'piped', 'smart']
+ description: Preferred method to use when transferring files over ssh
+ choices:
+ sftp: This is the most reliable way to copy things with SSH.
+ scp: Deprecated in OpenSSH. For OpenSSH >=9.0 you must add an additional option to enable scp C(scp_extra_args="-O").
+ piped: Creates an SSH pipe with C(dd) on either side to copy the data.
+ smart: Tries each method in order (sftp > scp > piped), until one succeeds or they all fail.
+ default: smart
type: string
env: [{name: ANSIBLE_SSH_TRANSFER_METHOD}]
ini:
@@ -317,24 +319,6 @@ DOCUMENTATION = '''
vars:
- name: ansible_ssh_transfer_method
version_added: '2.12'
- scp_if_ssh:
- deprecated:
- why: In favor of the O(ssh_transfer_method) option.
- version: "2.17"
- alternatives: O(ssh_transfer_method)
- default: smart
- description:
- - "Preferred method to use when transferring files over SSH."
- - When set to V(smart), Ansible will try them until one succeeds or they all fail.
- - If set to V(True), it will force 'scp', if V(False) it will use 'sftp'.
- - For OpenSSH >=9.0 you must add an additional option to enable scp (C(scp_extra_args="-O"))
- - This setting will overridden by O(ssh_transfer_method) if set.
- env: [{name: ANSIBLE_SCP_IF_SSH}]
- ini:
- - {key: scp_if_ssh, section: ssh_connection}
- vars:
- - name: ansible_scp_if_ssh
- version_added: '2.7'
use_tty:
version_added: '2.5'
default: true
@@ -389,6 +373,7 @@ import io
import os
import pty
import re
+import selectors
import shlex
import subprocess
import time
@@ -401,11 +386,8 @@ from ansible.errors import (
AnsibleError,
AnsibleFileNotFound,
)
-from ansible.errors import AnsibleOptionsError
-from ansible.module_utils.compat import selectors
from ansible.module_utils.six import PY3, text_type, binary_type
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
-from ansible.module_utils.parsing.convert_bool import BOOLEANS, boolean
from ansible.plugins.connection import ConnectionBase, BUFSIZE
from ansible.plugins.shell.powershell import _parse_clixml
from ansible.utils.display import Display
@@ -746,8 +728,8 @@ class Connection(ConnectionBase):
self._add_args(b_command, b_args, u'disable batch mode for sshpass')
b_command += [b'-b', b'-']
- if display.verbosity > 3:
- b_command.append(b'-vvv')
+ if display.verbosity:
+ b_command.append(b'-' + (b'v' * display.verbosity))
# Next, we add ssh_args
ssh_args = self.get_option('ssh_args')
@@ -1240,31 +1222,13 @@ class Connection(ConnectionBase):
# Transfer methods to try
methods = []
- # Use the transfer_method option if set, otherwise use scp_if_ssh
+ # Use the transfer_method option if set
ssh_transfer_method = self.get_option('ssh_transfer_method')
- scp_if_ssh = self.get_option('scp_if_ssh')
- if ssh_transfer_method is None and scp_if_ssh == 'smart':
- ssh_transfer_method = 'smart'
- if ssh_transfer_method is not None:
- if ssh_transfer_method == 'smart':
- methods = smart_methods
- else:
- methods = [ssh_transfer_method]
+ if ssh_transfer_method == 'smart':
+ methods = smart_methods
else:
- # since this can be a non-bool now, we need to handle it correctly
- if not isinstance(scp_if_ssh, bool):
- scp_if_ssh = scp_if_ssh.lower()
- if scp_if_ssh in BOOLEANS:
- scp_if_ssh = boolean(scp_if_ssh, strict=False)
- elif scp_if_ssh != 'smart':
- raise AnsibleOptionsError('scp_if_ssh needs to be one of [smart|True|False]')
- if scp_if_ssh == 'smart':
- methods = smart_methods
- elif scp_if_ssh is True:
- methods = ['scp']
- else:
- methods = ['sftp']
+ methods = [ssh_transfer_method]
for method in methods:
returncode = stdout = stderr = None
diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py
index b297495..c6a4683 100644
--- a/lib/ansible/plugins/connection/winrm.py
+++ b/lib/ansible/plugins/connection/winrm.py
@@ -2,8 +2,7 @@
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (annotations, absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
author: Ansible Core Team
@@ -148,8 +147,8 @@ DOCUMENTATION = """
seconds higher than the WS-Man operation timeout, thus make the connection more
robust on networks with long latency and/or many hops between server and client
network wise.
- - Setting the difference bewteen the operation and the read timeout to 10 seconds
- alligns it to the defaults used in the winrm-module and the PSRP-module which also
+ - Setting the difference between the operation and the read timeout to 10 seconds
+ aligns it to the defaults used in the winrm-module and the PSRP-module which also
uses 10 seconds (30 seconds for read timeout and 20 seconds for operation timeout)
- Corresponds to the C(operation_timeout_sec) and
C(read_timeout_sec) args in pywinrm so avoid setting these vars