Commit Graph

94 Commits (92feda2e1354ba419e8e25e11aeedac452c713aa)

Author SHA1 Message Date
Abhijeet Kasurde 92feda2e13
paramiko_ssh: remove deprecated ssh_*_args parameters (#82988)
* removed ssh_args parameter
* removed ssh_extra_args parameter
* removed ssh_common_args parameter

Fixes: #82939
Fixes: #82940
Fixes: #82941

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2 months ago
Matt Clay 9f899f9492
Require `from __future__ import annotations` (#81902) 8 months ago
Jordan Borean c3f479e378
Add type annotation for connection plugins (#78552)
* Add type annotation for connection plugins

* Use new | syntax instead of Union/Optional

* Fix pep issue

* Use ParamSpec and other minor fixes

* Fix up ParmaSpec args and kwargs type
11 months ago
Felix Fontein 7cf15d0732
Use semantic markup for remaining plugins. (#81189)
also change  `ansible_psrp_protocol` for `protocol`  as what matters is the option itself, not what was used to set it
11 months ago
Felix Fontein 440b5fd040
Make sure that values that should be strings are actually strings. (#81029) 12 months ago
Matt Clay 2cd1744be3
Use ansible.module_utils.common.text.converters (#80704)
Replace use of old `ansible.module_utils._text` and add a unit test to maintain backwards compatibility.
1 year ago
Brian Coca a1bff416ed
paramiko connection now uses the correct source of data (#79704)
* paramiko connection now uses the correct source of data

* keep orig name

* added missing port to docs

* Update changelogs/fragments/paramiko_config.yml

Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>

* test ansible_host templating

* added missing private_key_file

* removed all play_context fallbacks

* Update lib/ansible/plugins/connection/paramiko_ssh.py

Co-authored-by: Jordan Borean <jborean93@gmail.com>

* Update lib/ansible/plugins/connection/paramiko_ssh.py

Co-authored-by: Jordan Borean <jborean93@gmail.com>

---------

Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
Co-authored-by: Jordan Borean <jborean93@gmail.com>
1 year ago
Sloane Hertel b981a9dfcd
add a worker queue to get updates from the main results thread (#79886)
* Create a queue per WorkerProcess to receive intra-task updates
* Update `pause` action to use the worker queue
* Deprecate ConnectionBase()._new_stdin
* Add new `Display`  convenience method `prompt_until` to manage both controller- and worker-sourced prompting without cross-fork stdin sharing, in-worker mechanism to handle request-response over new worker queue.
1 year ago
Matt Martz 76b746655a
Add `use_rsa_sha2_algorithms` option for paramiko (#78789)
Fixes #76737
Fixes #77673

Co-authored-by: Matt Clay <matt@mystile.com>
2 years ago
Matt Martz 1b47def5ed
Add ssh_args and friends back, add var for proxy_command (#78826)
Fixes #78750
2 years ago
Andrew Latham 4604ea38dd
Supply some descriptions for settings used in ansible.cfg (#78536) 2 years ago
Brian Coca 04c7abcbfe
corrected version_added for new config option (#78013)
new option, not subs should have version, also it's 2.14
2 years ago
Ganesh Nalawade 1b1c2c79cf
Add configurable option for paramiko banner_ssh timeout (#68184)
* Add configurable option for paramiko banner_ssh timeout

This PR adds a configurable option for paramiko connection
to control the value of banner timeout in paramiko library.
The banner timeout value can be set in ansible.cfg file as
The default value of banner timeout is set to 30 seconds in
paramiko connection plugin.
```
[paramiko_connection]
banner_timeout = 30
```
or using enviornment variable
```
export ANSIBLE_PARAMIKO_BANNER_TIMEOUT=30
```

* Fix CI failure

* Fix review comments

* Fix review comment
2 years ago
Matt Clay 7c81a652c0 Type hint fixes. 2 years ago
Brian Coca 6d2d476113
avoid polluting vars with incorrect settings (#76590)
avoid polluting vars with incorrect settings

 simplify variables and templars
  - variables, original, only updated with final results, reset are copies of this
  - tempvars used for preliminary templating
  - cvars used for connection/shell/become plugins, delegation aware
  - vars_copy ignore tempvars updates and use connection plugin to get 
    finalized version per loop item/delegation,  also used to store temp results
    till we are ready to update 'variables'
 - fine tune nolog just cause we are here
 - also fix inventory_hostname_short for IP addresses
2 years ago
Brian Coca 864c2591b6
Use explicit keyword for plugin config (#75158)
* go back to keyword being explicit for plugin configs instead of using option name as implicit match
* switch spec to singular, no changes needed since no one used
2 years ago
Martin Krizek 0f95371131
Start of moving away from six (#75863)
ci_complete
3 years ago
Matt Martz 8d1cf7f266
Vendor `distutils.version` (#74644)
* Vendor distutils.version

* Fix import order. ci_complete

* remove distutils warning filter

* Don't remove warnings filter from importer

* ci_complete

* Add pylint config for preventing distutils.version

* Add changelog fragment
3 years ago
Sam Doran 74b2add460
paramiko_ssh - mark connection as connected when successful (#74459)
* Remove unused import from test
3 years ago
Matt Martz a3b6485073
Fix reset_connection paramiko, winrm, psrp (#72688)
* Ensure we only reset the connection when one has been previously established. Fixes #65812

* Ensure psrp doesn't trace

* winrm too

* Indentation fix
4 years ago
Felix Fontein aff78f4cbc
Fix various sanity errors in plugins (#71736)
* Fix various sanity errors in plugins.

* Revert callback_type -> type transform.

* Undo paramiko_ssh 'connection' change, since this discrepancy is hardcoded in the plugin loader.

* Standardize on name and type (for callbacks).

* Fix existing author entries.

* Add 'Unknown (!UNKNOWN)' as author when author is missing.

* These are actually parsed as integers in the code.

* Revert "Add 'Unknown (!UNKNOWN)' as author when author is missing."

This reverts commit 29d1438aca.
4 years ago
Rick Elrod 8e19ab178a
connection plugins: try config, then play_context (#69751)
Change:
Rather than only using config, have base connection plugins fall back to
play_context.

Test Plan:
- Tested ansible-connection logic against an IOS device
- Tested -k against a VM
- CI

Signed-off-by: Rick Elrod <rick@elrod.me>
4 years ago
Rick Elrod 8b6c02fc69
Make connection plugins use password from config (#69670)
Change:
Rather than connection plugins directly accessing play_context and pulling
the password from there, have them pull it from the config system, and
have TaskExecutor store it there for now.

Internally, it still routes through play_context for now, but this is
the first step away from that.

Test Plan:
- Local test with `ansible -c ssh`
- grep -R play_context.pass lib/ansible/plugins/connection/
- CI

Signed-off-by: Rick Elrod <rick@elrod.me>
4 years ago
Chris Holland d42151e676
Removed redundant conditional in paramiko_ssh.py (#69164)
* Removed redundant conditional

* Added changelog fragment

* Removed trailing whitespace
4 years ago
Paul Belanger adf73d47ec
Remove unused imports from paramiko_ssh connection (#66948)
These were caught by flake8 testing for ansible.netcommon collection.

Signed-off-by: Paul Belanger <pabelanger@redhat.com>
4 years ago
Mads Jensen ec34235e2e Use a context handler for file handling in paramiko_ssh.Connection. (#65624) 4 years ago
Jordan Borean 480b106d65
become - stop using play context in more places (#62373)
* become - stop using play context in more places - ci_complete

* Fix up review points
5 years ago
Sam Doran d5fbe6573b
paramiko_ssh - Improve authentication error message (#64157)
The error is not always an invalid username/password. It could be a connection timeout or refusal.
5 years ago
Sam Doran 6ce9cf7741
Change default smart connection to ssh on macOS and remove paramiko from requirements.txt (#54738)
* Remove default use of paramiko connection plugin on macOS
    This fix was originally to work around a bug that caused a kernel panic on macOS
    that has since been fixed.
* Remove paramiko from requirements.txt
* Move paramiko checking to common place
* Drop the warnings obfiscation code
* Update pip installation instructions to reflect upstream instructions
* Fix tests on CentOS 6 (Python 2.6) that now show Python deprecation warnings
* Add changelog fragment
5 years ago
Toshio Kuratomi b03c16fa8b
Paramiko might not come standard everywhere (#54486)
* Paramiko might not come standard everywhere

There is a platform where paramiko isn't shipped but a special version
of paramiko just for our use is shipped.  This code imports paramiko
from that location.
5 years ago
Brian Coca c09d11ad35
Revert "use get_optoins instead of play_context for user (#52604)" (#53034)
This reverts commit cf6a92d268.
5 years ago
Brian Coca cf6a92d268
use get_optoins instead of play_context for user (#52604)
fill in missing data
  fixes #52103
5 years ago
Matt Martz c55317a2bd
Update connection plugins to use correct, non-deprecated, methods (#52038)
* Update connection plugins to use correct, non-deprecated, methods

* Update tests to reflect calling become plugins
5 years ago
Matt Martz 445ff39f94
Become plugins (#50991)
* [WIP] become plugins

Move from hardcoded method to plugins for ease of use, expansion and overrides
  - load into connection as it is going to be the main consumer
  - play_context will also use to keep backwards compat API
  - ensure shell is used to construct commands when needed
  - migrate settings remove from base config in favor of plugin specific configs
  - cleanup ansible-doc
  - add become plugin docs
  - remove deprecated sudo/su code and keywords
  - adjust become options for cli
  - set plugin options from context
  - ensure config defs are avaialbe before instance
  - refactored getting the shell plugin, fixed tests
     - changed into regex as they were string matching, which does not work with random string generation
     - explicitly set flags for play context tests
 - moved plugin loading up front
 - now loads for basedir also
 - allow pyc/o for non m modules
 - fixes to tests and some plugins
 - migrate to play objects fro play_context
 - simiplify gathering
 -  added utf8 headers
 - moved option setting
 - add fail msg to dzdo
 - use tuple for multiple options on fail/missing
 - fix relative plugin paths
 - shift from play context to play
 - all tasks already inherit this from play directly
 - remove obsolete 'set play'
 - correct environment handling
 - add wrap_exe option to pfexec
 - fix runas to noop
 - fixed setting play context
 - added password configs
 - removed required false
 - remove from doc building till they are ready

future development:
  - deal with 'enable' and 'runas' which are not 'command wrappers' but 'state flags' and currently hardcoded in diff subsystems

* cleanup

  remove callers to removed func
  removed --sudo cli doc refs
  remove runas become_exe
  ensure keyerorr on plugin
  also fix backwards compat, missing method is attributeerror, not ansible error
  get remote_user consistently
  ignore missing system_tmpdirs on plugin load
  correct config precedence
  add deprecation
  fix networking imports
  backwards compat for plugins using BECOME_METHODS

* Port become_plugins to context.CLIARGS

This is a work in progress:
* Stop passing options around everywhere as we can use context.CLIARGS
  instead

* Refactor make_become_commands as asked for by alikins

* Typo in comment fix

* Stop loading values from the cli in more than one place

Both play and play_context were saving default values from the cli
arguments directly.  This changes things so that the default values are
loaded into the play and then play_context takes them from there.

* Rename BECOME_PLUGIN_PATH to DEFAULT_BECOME_PLUGIN_PATH

As alikins said, all other plugin paths are named
DEFAULT_plugintype_PLUGIN_PATH.  If we're going to rename these, that
should be done all at one time rather than piecemeal.

* One to throw away

This is a set of hacks to get setting FieldAttribute defaults to command
line args to work.  It's not fully done yet.

After talking it over with sivel and jimi-c this should be done by
fixing FieldAttributeBase and _get_parent_attribute() calls to do the
right thing when there is a non-None default.

What we want to be able to do ideally is something like this:

class Base(FieldAttributeBase):
    _check_mode = FieldAttribute([..] default=lambda: context.CLIARGS['check'])

class Play(Base):
    # lambda so that we have a chance to parse the command line args
    # before we get here.  In the future we might be able to restructure
    # this so that the cli parsing code runs before these classes are
    # defined.

class Task(Base):
    pass

And still have a playbook like this function:

---
- hosts:
  tasks:
  - command: whoami
    check_mode: True

(The check_mode test that is added as a separate commit in this PR will
let you test variations on this case).

There's a few separate reasons that the code doesn't let us do this or
a non-ugly workaround for this as written right now.  The fix that
jimi-c, sivel, and I talked about may let us do this or it may still
require a workaround (but less ugly) (having one class that has the
FieldAttributes with default values and one class that inherits from
that but just overrides the FieldAttributes which now have defaults)

* Revert "One to throw away"

This reverts commit 23aa883cbed11429ef1be2a2d0ed18f83a3b8064.

* Set FieldAttr defaults directly from CLIARGS

* Remove dead code

* Move timeout directly to PlayContext, it's never needed on Play

* just for backwards compat, add a static version of BECOME_METHODS to constants

* Make the become attr on the connection public, since it's used outside of the connection

* Logic fix

* Nuke connection testing if it supports specific become methods

* Remove unused vars

* Address rebase issues

* Fix path encoding issue

* Remove unused import

* Various cleanups

* Restore network_cli check in _low_level_execute_command

* type improvements for cliargs_deferred_get and swap shallowcopy to default to False

* minor cleanups

* Allow the su plugin to work, since it doesn't define a prompt the same way

* Fix up ksu become plugin

* Only set prompt if build_become_command was called

* Add helper to assist connection plugins in knowing they need to wait for a prompt

* Fix tests and code expectations

* Doc updates

* Various additional minor cleanups

* Make doas functional

* Don't change connection signature, load become plugin from TaskExecutor

* Remove unused imports

* Add comment about setting the become plugin on the playcontext

* Fix up tests for recent changes

* Support 'Password:' natively for the doas plugin

* Make default prompts raw

* wording cleanups. ci_complete

* Remove unrelated changes

* Address spelling mistake

* Restore removed test, and udpate to use new functionality

* Add changelog fragment

* Don't hard fail in set_attributes_from_cli on missing CLI keys

* Remove unrelated change to loader

* Remove internal deprecated FieldAttributes now

* Emit deprecation warnings now
5 years ago
James Cassell 953058d025 standardize connection variable names (#51776)
* standardize user/password connection vars

* docs: use ansible_user and ansible_password

* docs: var precedence for connection vars

* docs: ansible_become_pass -> ansible_become_password etc
5 years ago
Jordan Borean 6d13acf1ff
Ignore AttributeError when trying to import p paramiko (#51243)
* Ignore AttributeError when trying to import p paramiko

* preserve import error
5 years ago
Sam Doran 9d4c0dc111 Catch sshpass authentication errors and don't retry multiple times to prevent account lockout (#50776)
* Catch SSH authentication errors and don't retry multiple times to prevent account lock out

Signed-off-by: Sam Doran <sdoran@redhat.com>

* Subclass AnsibleAuthenticationFailure from AnsibleConnectionFailure

Use comparison rather than range() because it's much more efficient.

Signed-off-by: Sam Doran <sdoran@redhat.com>

* Add tests

Signed-off-by: Sam Doran <sdoran@redhat.com>

* Make paramiko_ssh connection plugin behave the same way

Signed-off-by: Sam Doran <sdoran@redhat.com>

* Add changelog

Signed-off-by: Sam Doran <sdoran@redhat.com>
5 years ago
Renato Orgito 6f9bca9de3 Add auth_timeout parameter when supported by paramiko (#50448)
* Add auth_timeout parameter when supported

Paramiko 2.2 introduces the auth_timeout parameter. This will set the
parameter to the same value of the timeout parameter to prevent
"Authentication timeout" errors.

* Conditionally add auth_timeout to ssh.connect

Renamed sock_kwarg to ssh_connect_kwargs and conditionally added the
auth_timeout parameter based on the installed paramiko version.

* Add changelog fragment
5 years ago
Sam Doran 8f9ced4005 Improve log message (#49004)
This is the only connection plugin that doesn't state explicitly what it is in the log.
6 years ago
Sam Doran 5eb7f5781e
Reboot - Fix errors when using Paramiko connection (#49002)
Different connection plugins return different data when throwing exceptions. The Paramiko connection plugin does not return a text sting, which caused an exception.

The ssh connection plugin returns multi-line errors, which makes the debug logs harder to read. Only return the last line in that case in order to make the logs more readable.

When experiencing a connection failure, reset the connection.

Add reset() to paramiko_ssh

Indicate thet conection state is False when running close(). This is needed by the ensure_connected() decorator to work properly.


Co-authored-by: Matt Martz <matt@sivel.net>
6 years ago
Matt Martz 9773a1f289
Add a Singleton metaclass, use it with Display (#48935)
* Add a Singleton class, use it with Display

* update six import

* Move remaining failes to display singleton

* Fix rebase issues

* Singleton improvements

* Add code-smell for 'from __main__ import display'. ci_complete

* s/self/cls/g

* Add docs for no-main-display

* Address linting issues

* Add changelog fragment. ci_complete

* Implement reentrant lock for class instantiation in Singleton

* Add Display singleton porting guide
6 years ago
Martin Krizek a80c25cbd9
Do not use str() on exceptions (#46950) 6 years ago
Dag Wieers 2974df9d5e
Fix typo 6 years ago
Ricardo Carrillo Cruz 62e1c14edc
Pull persistent connection parameters via get_option (#39367)
* WIP Pull persistent connection parameters via get_option

* Fix pep8

* Add use_persistent_connection setting to paramiko_ssh plugin

* Add vars section to persistent_command_timeout setting and prevail provider values over config manager

* Use persistent_command_timeout on network_cli instead of timeout

* Fix unit tests

If we don't call loader to get network_cli, then _load_name is never
set and we get KeyError.

* Pull persistent_command_timeout via config  manager for ios connection local

* Pull persistent_command_timeout via config manager on connection local
6 years ago
jctanner bbfe7a8b2f
more debug logs for free, network_cli, paramiko and add hostname context to debugging messages (#39205)
* Add hostname context to debugging messages
* Set paramiko's channel
6 years ago
Nathaniel Case e8755175d7
Fix paramiko connections to hosts with uppercase characters (#35555) 6 years ago
bdowling 5b6ba8cbfd Minor spelling fix (#33822) 7 years ago
John R Barker 4d67cdd1f7
Use module formatting (#33413) 7 years ago
Brian Coca 22d983c5c1
get_option instead of internal dict (#33191)
* get_option instead of internal dict

* fix slack issue

* not a pugin, revert get_option
7 years ago
Nathaniel Case 37d8242e44
Fix hang on unkown host key for network_cli (#32937)
* Don't prompt on force_persistent either

* Propagate persistence setting to lower paramiko connection
7 years ago