Commit Graph

45 Commits (179bc1dabd9b3221b36da08d7913dfdba177cc6b)

Author SHA1 Message Date
Jordan Borean 179bc1dabd
fetch - add error check on calculated dest (#82970)
Add explicit error when the calculated dest path for fetch becomes a
local directory. The existing behaviour will not be checked unlike when
the path did not end with a trailing slash.
2 months ago
Brian Coca 3d9e5c8b9d
fix pc misuse (#82157)
use the more up to date 'task' as play_context only has the 'initial' values.
7 months ago
Matt Clay 9f899f9492
Require `from __future__ import annotations` (#81902) 8 months ago
Matt Martz aa67d544fc
Handle unreachable errors in fetch properly. Fixes #27816 (#80952) 1 year ago
Sam Doran be0cdc0ea2
deprecate `_remote_checksum()` and remove use in fetch (#74848)
* Remove use of _remote_checksum from fetch module
* Add deprecation message displayed during runtime
* Increase test coverage for fetch
* Add tests covering the use of stat from the fetch module

    This required creating an unpriveleged user account and connecting as that user remotely since
    it is not possible to create a file that the root user cannot stat.

* Use fact caching to persist remote tmp dir across playbook runs
* Add variables to setup_remote_tmp test role to allow caching of the remote temp dir fact
  and preventing removal of the remote_tmp_dir
3 years ago
Matt Davis 4c0af6c808
fix internal cases of actions calling unqualified module names (#70818)
* fix internal cases of actions calling unqualified module names

* add porting_guide entry
* misc other fixes around action/module resolution broken by redirection

ci_complete

* Update docs/docsite/rst/porting_guides/porting_guide_2.10.rst

Co-authored-by: Rick Elrod <rick@elrod.me>

* Update docs/docsite/rst/porting_guides/porting_guide_2.10.rst

Co-authored-by: Rick Elrod <rick@elrod.me>

* address review feedback

* pep8

* unit test fixes

* win fixes

* gather_facts fix module args ignores

* docs sanity

* pep8

* fix timeout test

* fix win name rewrites

Co-authored-by: Rick Elrod <rick@elrod.me>
4 years ago
Brian Coca ba87c225cd
fixed fetch traversal from slurp (#68720)
* fixed fetch traversal from slurp

  * ignore slurp result for dest
  * fixed naming when source is relative
  * fixed bug in local connection plugin
  * added tests with fake slurp
  * moved existing role tests into runme.sh
  * normalized on action excepts
  * moved dest transform down to when needed
  * added is_subpath check
  * fixed bug in local connection

fixes #67793

CVE-2019-3828
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
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
Matt Martz 0015d4cef3
2.8 Core Deprecation Removal (#45232)
* Remove deprecated ansible.vars.unsafe_proxy. Fixes #45040

* Remove deprecated validate_md5 alias from fetch module. Fixes #45039

* Remove deprecated private arg from import/include_role. Fixes #45038

* All include deprecations bumped to 2.12. Fixes #45037

* Add changelog for deprecated removals
6 years ago
Matt Martz c1c229c6d4
Remove use of simplejson throughout code base (#43548)
* Remove use of simplejson throughout code base. Fixes #42761

* Address failing tests

* Remove simplejson from contrib and other outlying files

* Add changelog fragment for simplejson removal
6 years ago
Jordan Borean df8a5d7a4f
fetch: set fail_on_missing: True as default as per docs (#36469)
* fetch: set fail_on_missing: True as default as per docs

* Updated docs for fetch to say behaviour was changed in 2.5 and updated tests
6 years ago
Toshio Kuratomi 06f73ad578
Normalize usage of temp and tmp on tmp (#36221)
* Normalize usage of temp and tmp on tmp
* Rename system_tmps system_tmpdirs
* Add ANSIBLE_REMOTE_TMP spelling of environment variables
6 years ago
Toshio Kuratomi 71f46d69d6 First bit of fixing temporary to have one source of truth (#35747)
* First bit of fixing temporary to have one source of truth

* Fix pep8

* Remove explicit make_tmp_path() in copy

The copy action plugin sets TRANSFER_FILES=True so it does not need to
set the temporary directory explicitly; the base class's run() method
will do that for us.

* Fix for calling a module's run when a shell has already created a temp path.

* Remember to inform the rest of the world when tempdir is removed

* New strategy for how to warn on passing tmp

Now we just warn when calling the parent class run() early.  If the
module does a late call to the parent run() and doesn't make use of the
temporary directory, then we don't check for the possibility that the
user mistakenly is sending tmp in.  If we truly deprecate this (rather
than ignoring it forever) then we might want to switch back to checking
for someone passing a value in as tmp.

* Remove tmp parameter from _execute_module as well

* Port all action plugins to not send tmp explicitly

This is now handled inside of _execute_module via the
_connection._shell.tempdir attribute.

Also update warnings and docs to tell people to set the attribute
instead of using _execute_module's tmp parameter.

* Always set local tempdir variable
6 years ago
Jordan Borean 389f4ef1fb
template: change to pass along the correct template path (#35027)
* template: change to pass along the correct template path

* standardise tmp path behaviour

* removed if condition as it should not be needed
6 years ago
Brian Coca bbd6b8bb42 Temporary (#31677)
* allow shells to have per host options, remote_tmp

added language to shell
removed module lang setting from general as  plugins have it now
use get to avoid bad powershell plugin
more resilient tmp discovery, fall back to `pwd`
add shell to docs
fixed options for when frags are only options
added shell set ops in t_e and fixed option frags
normalize tmp dir usag4e

- pass tmpdir/tmp/temp options as env var to commands, making it default for tempfile
- adjusted ansiballz tmpdir
- default local tempfile usage to the configured local tmp
- set env temp in action

add options to powershell
shift temporary to internal envvar/params
ensure tempdir is set if we pass var
ensure basic and url use expected tempdir
ensure localhost uses local tmp
give /var/tmp priority, less perms issues
more consistent tempfile mgmt for ansiballz
made async_dir configurable
better action handling, allow for finally rm tmp
fixed tmp issue and no more tempdir in ballz
hostvarize world readable and admin users
always set shell tempdir
added comment to discourage use of exception/flow control

* Mostly revert expand_user as it's not quite working.

This was an additional feature anyhow.

Kept the use of pwd as a fallback but moved it to a second ssh
connection.  This is not optimal but getting that to work in a single
ssh connection was part of the problem holding this up.

(cherry picked from commit 395b714120522f15e4c90a346f5e8e8d79213aca)

* fixed script and other action plugins

ensure tmpdir deletion
allow for connections that don't support new options (legacy, 3rd party)
fixed tests
6 years ago
Martin Krizek 36c6d0f748 fetch: fail if flat=yes and dest=existing-dir w/o trailing slash 7 years ago
Toshio Kuratomi ff22528b07 Consolidate boolean/mk_boolean conversion functions into a single location
Consolidate the module_utils, constants, and config functions that
convert values into booleans into a single function in module_utils.

Port code to use the module_utils.validate.convert_bool.boolean function
isntead of mk_boolean.
7 years ago
Brian Coca c4169d93e8 add validation to fetch for source/dest
also added missing display
7 years ago
Dag Wieers 5553b20828 Collated PEP8 fixes (#25293)
- Make PEP8 compliant
7 years ago
Toshio Kuratomi a0dfa8616a Make fetch default to fail on errors
Fixes #23501
7 years ago
Toshio Kuratomi bffccb5396 fetch idempotence test and deprecate validate_md5
Added an integration test for fetch module idempotence.  (Testing
that validate_checksum is doing what it's supposed to is harder as we'd
have to create a race condition with the downloaded data to trigger it.
Probably need to make that a unittest eventually).

Also give a deprecation message to the validate_md5 parameter so that we
can eventually get rid of it.
7 years ago
KeepZero 98e7d4b49d Set validate_checksum default yes of fetch to match the doc 7 years ago
Brian Coca ca1514cf2a unified boolean function
optimized boolean function
fixes #17815
8 years ago
Brian Coca 680cade77a simplified the code by removing repeats
(cherry picked from commit 84380b0ee4029212fc1637c008e07bb9958305c3)
8 years ago
Toshio Kuratomi 4ed88512e4 Move uses of to_bytes, to_text, to_native to use the module_utils version (#17423)
We couldn't copy to_unicode, to_bytes, to_str into module_utils because
of licensing.  So once created it we had two sets of functions that did
the same things but had different implementations.  To remedy that, this
change removes the ansible.utils.unicode versions of those functions.
8 years ago
Toshio Kuratomi f57f33a8e7 Fix fetch idempotence (#17255)
Fetch always follows symlinks when downloading so it needs to always
follow symlinks when getting the checksum of the file as well.
8 years ago
Matt Clay f878a5d2e0 Fix unicode handling in connection plugins. 8 years ago
Toshio Kuratomi 36aa89ac7e Fix erroneous fetch fail when fail_on_missing is set to False
Fixes #13832
9 years ago
Brian Coca fb96748d7c fixes to fetch action module
* now only runs remote checksum when needed (fixes #12290)
 * unified return points to simplify program flow
9 years ago
Toshio Kuratomi 2e87c1f74e Two fixes to action plugins
* Fix the task_vars parameter to not default to a mutable type (dict)
* Implement invocation in the base class's run() method have each action
  module call the run() method's implemention in the base class.
* Return values from the action plugins' run() method takes the return
  value from the base class run() method into account so that invocation
  makes its way to the output.

Fixes #12869
9 years ago
Toshio Kuratomi c6d44738ad Clean up some more pyflakes warnings 9 years ago
Toshio Kuratomi a1428d6bed Remove tmp as a parameter to the connection plugins
There doesn't appear to be anything that actually uses tmp_path in the
connection plugins so we don't need to pass that in to exec_command.
That change also means that we don't need to pass tmp_path around in
many places in the action plugins any more.  there may be more cleanup
that can be done there as well (the action plugin's public run() method
takes tmp as a keyword arg but that may not be necessary).

As a sideeffect of this patch, some potential problems with chmod and
the patch, assemble, copy, and template modules has been fixed (those
modules called _remote_chmod() with the wrong order for their
parameters.  Removing the tmp parameter fixed them.)
9 years ago
Chris Church 260b9f648c Fix fetch action plugin to not fail if file is missing and fail_if_missing=False (the default). Add tests to test_fetch role to verify it works as expected. 9 years ago
James Cammarata fca27c29f4 Properly fail if slurp fails during fetch 9 years ago
James Cammarata 66a2f2923e Look for proper values in slurp result during fetch with become enabled 9 years ago
James Cammarata 4836641683 Use ansible_python_interpreter value for remote checksums
Fixes #11968
Fixes #11969
9 years ago
Chris Church e87cf4a3cc Fixes for WinRM/PowerShell support in v2.
- Add support for inserting module args into PowerShell modules.  Fixes #11661.
- Support Windows paths containing spaces.  Applies changes from #10727 to v2.  Fixes #9999.  Should also fix ansible/ansible-modules-core#944 and ansible/ansible-modules-core#1007.
- Change how execution policy is set for running remote scripts.  Applies changes from #11092 to v2.  Also fixes ansible/ansible-modules-core#1776.
- Use codepage 65001 (UTF-8) for WinRM connection instead of default (CP437), convert command to UTF-8 and results from UTF-8.  Replaces changes from #10024.  Fixes #11198.
- Close WinRM connection when task completes.
- Use win_stat, win_file and win_copy modules instead of stat, file and copy when called from within other action plugins (only when using WinRM+PowerShell).
- Unquote Windows path arguments before passing to win_stat, win_file, win_copy and slurp modules (only when using WinRM/PowerShell).
- Check for win_ping module to determine if core modules are missing (only when using WinRM/PowerShell).
- Add stdout_lines to result from running low level commands (so stdout_lines is available when using raw/script).
- Update copy action plugin to use shell functions for joining paths and checking for trailing slash.
- Update fetch action plugin to unquote source path when using Windows paths.
- Add win_copy and win_template action plugins that inherit from copy and template.
- Support running .bat and .cmd scripts using default system encoding instead of UTF-8.
- Always send PowerShell commands as base64-encoded blobs to allow for running simple PowerShell commands via raw.
- Support running modules on Windows with interpreters other than PowerShell.
- Update integration tests to support above changes and test unicode fixes.
- Add test for win_user error from ansible/ansible-modules-core#1241 (fixed by ansible/ansible-modules-core#1774).
- Add test for additional win_stat output values (implemented by ansible/ansible-modules-core#1473).
- Add test for OS architecture and name from setup.ps1 (implemented by ansible/ansible-modules-core#1100).

All WinRM integration tests pass for me with these changes.
9 years ago
James Cammarata 7a9916422a Fixing up error handling for fetch_file ops in connection plugins
* enable batch mode (configurable with a config option, on by default)
  for sftp transfers, so we can catch errors more easily
* general cleanup in the local connection plugin and fetch action plugin

Fixes #11612
9 years ago
James Cammarata e64989beb4 Moving ConnectionInformation -> PlayContext
Also making PlayContext a child class of the Playbook Base class,
which gives it access to all of the FieldAttribute code to ensure
field values are correctly typed after post_validation

Fixes #11381
9 years ago
James Cammarata cf51d0a790 Fixing up some check-mode stuff 9 years ago
Pierre-Louis Bonicoli 4d4512940d Fix "AttributeError: 'ActionModule' object has no attribute '_shell'"
'_shell' was removed with commit 2a5fbd8570
9 years ago
James Cammarata ee5e166563 Fixing ansible_*_interpreter use
Fixes ansible/ansible-modules-core#1459
9 years ago
Brian Coca 2590df6df1 created makedirs_safe function for use in cases of multiprocess
should fix #11126 and most race conditions
9 years ago
James Cammarata ce3ef7f4c1 Making the switch to v2 9 years ago