Commit Graph

530 Commits (6cc97447aac5816745278f3735af128afb255c81)

Author SHA1 Message Date
Toshio Kuratomi b49be56c5b Need regex and string types to match when cleaning arguments for logging
Fixes #25078
9 years ago
Brian Coca 2a041d10d2 better backwards compat handling of status
restored 'rc' inspection but only when failed is not specified
removed redundant changed from basic.py as task_executor already adds
removed redundant filters, they are tests
added aliases to tests removed from filters
fixed test to new rc handling
9 years ago
Brian Coca d5f4c2a54b auto tb on vvv+ or debug (#26106)
* auto tb on vvv+ or debug

* updated as per feedback
9 years ago
Abhijeet Kasurde ba4f6de35a Add support for Devuan in hostname module (#25525)
Fixes #25395

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
9 years ago
Toshio Kuratomi 15104acc00 Fix json.dumps to do something sensible with sets. 9 years ago
Toshio Kuratomi be4e7a05fa remove_values could hit the recursion limit
When operating on arbitrary return data from modules, it is possible to
hit the recursion limit when cleaning out no_log values from the data.
To fix this, we have to switch from recursion to iteration.

Unittest for remove_values recursion limit

Fixes #24560
9 years ago
Dag Wieers 5553b20828 Collated PEP8 fixes (#25293)
- Make PEP8 compliant
9 years ago
Brian Coca 05caa3654c fix to alwasy use param in case subpec is used 9 years ago
Philippe Dellaert 3ae69302a2 Fixes ansible/ansible#25096 (#25098) 9 years ago
Dag Wieers 0e160d5c7e Ensure exit_json returns failed = False
This is required for modules that may return a non-zero `rc` value for a
successful run, similar to #24865 for Windows fixing **win_chocolatey**.

We also disable the dependency on `rc` value only, even if `failed` was
set.

Adapted unit and integration tests to the new scheme.
Updated raw, shell, script, expect to take `rc` into account.
9 years ago
Brian Coca e506b5da14 only set executable from shell if not set already 9 years ago
Brian Coca 55135c0825 enable run_command to use non /bin/sh shells
fixes #24169
9 years ago
Abhijeet Kasurde 764b4b20ec Fix UnboundLocalError in basic.py
* Fix for UnboundLocalError while accessing deprecations
  in result
* Add Unit test

Fixes #24592

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
9 years ago
Toshio Kuratomi 90a229c793 Fix error in unittesting
When unittesting, the framework creates a pipes module that is picked up
by the basic module_utils test.  Switch to using shlex_quote as that is
the right thing to use for portability anyway.
9 years ago
Toshio Kuratomi 36d7c0c403 Fix places where path needs to be bytes on python3
These were discovered on python3 with fetch code that fails on errors.  Probably could be
provoked with particular sets of arguments to stat as well.
9 years ago
Brian Coca 631a10745d fix hashing when path is symlink 9 years ago
Matt Clay 48eeab8a53 Fix errors reported by pylint. (#23282)
* Fix pylint misplaced-bare-raise errors.
* Fix pylint return-in-init error.
* Fix pylint bad-format-character error.
* Fix pylint too-many-format-args errors.
* Fix pylint too-few-format-args errors.
* Fix pylint truncated-format-string error.
9 years ago
Brian Coca ea7bff4a3f changed spec to options as per irc meeting 9 years ago
Brian Coca 9a05113daf pass params to validate against 9 years ago
Brian Coca 25de905c6e subspec protptype 9 years ago
Matt Martz 3164e8b561 E501 fixes (#22879) 9 years ago
Matt Martz 02f66b9369 E1 legacy pep8 fixes (#21933)
* E1 pep8 fixes

* e111 fix for rds.py
9 years ago
Brian Coca 07d9366ed8 added 'existing' back
fixes #22785
9 years ago
THEBAULT Julien 374d491ba5 Check if file is not a directory with get_bin_path function (#13985) 9 years ago
Viktor Fogelberg b9ed3454e4 Change comment to reflect the actual code 9 years ago
Dag Wieers 237411613d Ensure that filenames from archives are not expanded
This fixes #21795
9 years ago
Toshio Kuratomi 49194a66c8 Fix log_invocation function to pass unittests on python3
Normalize this function to use native strings.  Native strings won't
display an extra "u" or "b" character to denote py2 unicode or py3 bytes
types.
9 years ago
Matt Martz 305c88700d PEP8 E712 fixes (#21916) 9 years ago
Brian Coca 47870c3385 refine password field filtering (#21230)
* refine password field filtering

* dont skip

* removed bad leftover vestige of previous condition
9 years ago
Pilou f2c22109fb Don't mix deprecations messages with warnings messages (#21337)
* Remove unused attribute '_passthrough'

* Don't mix deprecations with warnings

* Return values: add 'deprecations' key used internally

* 'deprecations' and 'warnings' return values: add tests
9 years ago
Brian Coca 85194234ba fixed bad copy/paste, deprecations should deprecate 9 years ago
Toshio Kuratomi 98541b7c8b Fix to bytes surrogate and nonencodable chars (#21180)
* Add a surrogate_then_replace error strategy to keep to_bytes from tracebacking by default
* Port all code that explicitly used surrogate_or_replace to surrogate_then_replace
9 years ago
Brian Coca 403e9d35df use regex vs list to weed out password fields
- also warn as module SHOULD have no_log
 - make password regex exportable for testing
 - avoids boolean fields
9 years ago
Peter Sprygada 138051540e updates the code path for network modules (#21193)
* replaces persistent connection digest with _create_control_path()
* adds _ansible_socket to _legal_inputs in basic.py
* adds connection_user to play_context
* maps remote_user to connection_user when connection is local
* maps ansible_socket in task_vars to module_args _ansible_socket if exists
9 years ago
Brian Coca 2f1ab29855 add url_password to 'cleanse' list 9 years ago
jerry bd19a9e847 removing unwanted variables and using to_native instead of str()
(cherry picked from commit c4b09cbcb4)
9 years ago
jeronimog 4f85e4831d Adding self.log() on IOErrors and OSErrros
(cherry picked from commit ef1ecfd2c2)
9 years ago
René Moser 541a51ddf7 module_utils: implement deprecation warning for params (#20884)
* module_utils: implement deprecation warning for params

* rename deprecated_version to removed_in_version

* fix pep8 E121
9 years ago
Ganesh Nalawade 01f4d4a666 module_utils/basic.py: Support logical or condition in required_if (#20220)
* Support logical or condition in required_if

Add logical 'or' condition support in 'required_if'
for requirements.
* If requirements is a list all parameters within it should
  be present.
* If requirements is a set atleast one parameter should
  be present

* Fix review comment
9 years ago
Adrian Likins ee9ab6c665 Show valid bool symbols in error for invalid bool symbol 9 years ago
Brian Coca 7e6758873c added warnings list to module and autoadd
added better way of adding warnings to return data
backwards compatible if warnings key already exists
added deprecations made iface more generic
changed to enforce type per item
added logging of warnings/deprecations
also display deprecations by default
9 years ago
Matt Clay cb76200c7d PEP 8 E111 & E114 cleanup. (#20838) 9 years ago
Matt Clay 10d9318de7 PEP 8 indent cleanup. (#20800)
* PEP 8 E121 cleanup.

* PEP 8 E126 cleanup.

* PEP 8 E122 cleanup.
9 years ago
Matt Clay d0d1158c5e PEP 8 cleanup. (#20789)
* PEP 8 E703 cleanup.
* PEP 8 E701 cleanup.
* PEP 8 E711 cleanup.
* PEP 8 W191 and E101 cleanup.
9 years ago
Toshio Kuratomi 02e3f4b526 Fix for atomic_move on RHEL5
When becoming an unprivileged user using non-sudo on a platform where
getlogin() failed in our situation we were not able to detect that the
user had switched.  This meant that all of our logic to use move vs copy
if the user had switched was attempting the wrong thing.  This change
tries the to do the right thing but then falls back to an acceptable
second choice if it doesn't work.

The bug wasn't easily detected because:
* sudo was not affected because sudo records that the user's have been
  switched so we were able to detect that.
* getlogin() works on most platforms.  RHEL5 with python-2.4 seems to be
  the only platform we still care about where getlogin() fails for this
  case.
* It had to be becoming an unprivileged user.  When becoming
  a privileged user, the user would be able to successfully perform the
  best case tasks.
9 years ago
Brian Coca 92e8c53879 fixed id queries, should rely on effective 9 years ago
Toshio Kuratomi 70e42f917d Add traceback information to fail_json in atomic move 9 years ago
Gordon Gao d9e1e374b2 let chdir support relative path in more modules (#16736) 9 years ago
Brian Coca 7faa041636 added file flag preservation to atomic_move
preserves existing flag info if possible
9 years ago
Brian Coca 8c5d321a23 simplified unsafe writes 9 years ago
Brian Coca ebf835045f unique error messages to avoid confusion 9 years ago
Adrian Likins ab560df15f Fix 3 char indent on AnsibleModule._unsafe_writes (#19542) 9 years ago
Adrian Likins 2597c1236d Better error msg for basic.get_bin_path()
Include the searched paths in the error message.
9 years ago
Adrian Likins 35fef6fb84 Better error message for module unsupported params
Keep track of all the unsupported parameters, and include
all of them in the error message as well as a list of the
supported params.
9 years ago
Steve Kuznetsov d5324c11a0 Factored polling std{out,err} reads into a function
The process to poll for data in the stdout and/or stderr pipes during a
low-level command execution was repetitive. Factoring this out into a
function DRYs out the code.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
9 years ago
Andrea Tartaglia 59227d8c31 Removed dict.iteritems() in several other files.
This is for py3 compatibility #18506
9 years ago
Brian Coca 461dcf8ce3 log on target based on nolog, not verbosity (#18570)
* log on target based on nolog, not verbosity

fies #18569

* initialize module name

removing verbosity exposed missing name at certain stages, initialize to file name
and update later once module args are parsed
9 years ago
Adrian Likins dbbd2d79ff Fix traceback in atomic_move (#18649)
Commit 8b08a28c89 removed a
call to get_exception() that was needed. Without it, the fail_json
references an undefined variable ('exception') and throws an exception.

Add the get_exception() back in where needed and update references.

Now the proper module failure is returned.

Fixes #18628
9 years ago
Brian Coca a0f27d552c File attributes (#18213)
* added attributes to base file params

* dont change attributes when none

* fixed test to deal with new attributes
9 years ago
Toshio Kuratomi fda933723c Add hint that python3 might be too old
This limitation of python-3.4 mkstemp() is the final reason we made
python-3.5 our minimum version.  Since we know about it, give a nice
error to the user with a hint that Python3.4 could be the issue.

Fixes #18160
9 years ago
Toshio Kuratomi 08a58ae025 Fix for run_command tests now that it returns native strings 9 years ago
Toshio Kuratomi ddd20627a4 Make run_command return native strings
This changes the return value on python3   Return value on python2 was
already byte strings (which is the native str type there.)
9 years ago
Michael Scherer 362b682f1c Add a umask argument to run_command
In order to avoid problem due to race conditions, it is
required to run umask when generating some sensitive files,
such as a TLS key.
9 years ago
Pascal Grange 8b08a28c89 fixes issue #13981: unsafe_writes block appeared too late in the atom… (#17405)
* fixes issue #13981: unsafe_writes block appeared too late in the atomic_move
workflow. This led to errno.EBUSY to not be managed in the context of
issue #!#981

* Reduce changes to fix #13981

* Abstract the unsafe_writes fallback into a helper method.
Explicitly try/except os.rename part of the code and call this helper method.
If the code fails in shutil.copy2 or shutil.move this should not be related to issue #13981
since they write to b_tmp_dest_name.
(as suggested by @abadger)

* Check if unsafe_writes in the caller, not in _unsafe_writes.
That way the function call reads as "Do an unsafe write"
and not as "I think we should do an unsafe_write.
9 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.
9 years ago
Toshio Kuratomi f7b22a5eaa Fix paramiko's exec_command() to return bytes on python3 (#17372)
* Fix paramiko's exec_command() to return bytes on python3

* Run test_connection for python3 now too

* Fix atomic_move for problem in shippable's testing

* Python-2.4 needs to use b()
9 years ago
Toshio Kuratomi 67177105e3 We now have an exception return value. Make use of it instead of putting the traceback into msg (#17365) 9 years ago
Toshio Kuratomi 28227546fa Various python3 updates for module_utils: (#17345)
* Port set_*_if_different functions to python3
* Add surrogate_or_strict and surrogate_or_replace error handlers for
  to_text, to_bytes, to_native
* Set default error handler to surrogate_or_replace
* Make use of the new error handlers in the already ported code
* Move the unittests for module_utils._text as they aren't in basic.py
* Cleanup around SEQUENCETYPE.  On python2.6+ SEQUENCETYPE includes
  strings so make sure code omits those explicitly if necessary
* Allow arg_spec aliases to be other sequence types
9 years ago
Toshio Kuratomi 71ef25d5e8 For module parameter checking, allow conversion of int to float (#17325)
Fixes https://github.com/ansible/ansible-modules-core/issues/4084
9 years ago
Toshio Kuratomi fa804125b5 Python3 fixes and porting (#17271)
* Fix to_native call in selinux_context and selinux_default_context to
  use the error handler correctly.
* Port set_mode_if_different to work on python3
* Port atomic_move to work on python3
* Fix check_password_prompt variable which wasn't renamed properly
9 years ago
Peter Martini 15f10ab4bc Simple documentation typo fix, 'iIf' to 'If' 9 years ago
Alexander Stock 238cccf166 Fix "Text file busy" exception in atomic_move (#9526) (#17204)
tempfile.NamedTemporaryFile keeps a file handle causing os.rename() to fail with windows based vboxfs: [Errno 26] Text file busy.
Changed NamedTemporaryFile to mkstemp() and added a finally block to unlink the temp file in each and every case.
9 years ago
Toshio Kuratomi 4a3a9c0f2d Fix for run_command on py3 and enable lineinfile test on py3 (#17257)
* run_command needed a bit of tweaking to its string handling of
  arguments.
* The run_command change fixes the last bit of lineinfile so we can
  enable its tests
9 years ago
Toshio Kuratomi 0a39700b36 Fix octal output in a few more places (#17250)
Fix filetree lookup plugin for python3 (octal output and selinux API
takes native strings)
9 years ago
Yann Autissier 8fd3935029 Fix get_distribution for Alpine Linux (#17224)
To override a generic class that is subclassed based on platform, the
subclass must define platform and distribution.

The load_platform_subclass() calls the get_platform() and
get_distribution() methods to detect the platform and the distribution.

On Alpine Linux, get_distribution() method returns None and it is not
possible to have different implementations based on detected platform.
9 years ago
Matt Clay 178292d2cd Fix file and copy modules on py3 and enable tests. (#17239)
- Fix octal formatting of file mode in module response on py3.
- Convert file path to unicode in copy action.
- Enable file and copy module tests for py3 now that they pass.
9 years ago
Yannig 27b0f3241b new filter human_bytes: convert a string (ex: 1Mo, 1K) into bytes (#12074)
* Rework human_readable and human_to_bytes.
New filter human_to_bytes.

* Fix for python 3.
9 years ago
Toshio Kuratomi a22909c226 Migrate basestring to a python3 compatible type (#17199) 9 years ago
Michael Scherer b2476e7d99 Fix errors when using -vvvv with python 3 (#17186)
Traceback (most recent call last):
      File "/tmp/ansible_tpehdgt7/ansible_module_setup.py", line 134, in <module>
        main()
      File "/tmp/ansible_tpehdgt7/ansible_module_setup.py", line 124, in main
        supports_check_mode = True,
      File "/tmp/ansible_tpehdgt7/ansible_modlib.zip/ansible/module_utils/basic.py", line 696, in __init__
      File "/tmp/ansible_tpehdgt7/ansible_modlib.zip/ansible/module_utils/basic.py", line 1670, in _log_invocation
      File "/tmp/ansible_tpehdgt7/ansible_modlib.zip/ansible/module_utils/basic.py", line 469, in heuristic_log_sanitize
    TypeError: 'str' does not support the buffer interface
9 years ago
Toshio Kuratomi 57701d7115 Give native strings to selinux library functions. (#17184)
* Give native strings to selinux library functions.

SELinux takes pathnames as native strings.  That means we need to
convert to bytes on python2 and convert to text on python3.

Fixes #17155

* Read kitchen documentation, make module_utils params more like kitchen API

* Remove none nonstring strategy and add strict
* Raise TypeError on invalid nonstring strategy

* Document to_native()

* Make unittests for testing module_utils.text
9 years ago
Toshio Kuratomi 171a094805 Cleanup basic.py code now that six is available (#17158)
* Cleanup basic.py code now that six is available

We had some hacks in basic.py to allow us python2 and python3
compatibility.  Those can now be offloaded to the six library that we're
bundling.

* Cleanup basic.py code now that six is available

We had some hacks in basic.py to allow us python2 and python3
compatibility.  Those can now be offloaded to the six library that we're
bundling.
9 years ago
Brian Coca 297e2d8266 added bits and bytes arg types (#17102)
* added bits and bytes arg types

* changed function alias method as per feedback

* use enumerate vs managing i myself
9 years ago
Brian Coca 47e3366744 fixed indent 9 years ago
Brian Coca ea033ae2cc removed extraneous test code 9 years ago
Brian Coca eb0c90ab80 added unsafe_writes as common file feature (#17016) 9 years ago
Toshio Kuratomi 6db6edfc4f YAML treats some unquoted strings as booleans. For instance, (#16961)
uri:
    follow_redirects: no

Will lead yaml to set follow_redirects=False.  This is problematic when
the module parameter is not a boolean value but a string.  For instance:

  follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']),

Our parameter validation code ends up getting follow_redirects="False"
instead of "no".  The 100% fix is for the user to quote their strings in
playbooks like:
  uri:
    follow_redirects: "no"

But we can fix quite a few common cases by trying to switch "False" back
into the string that it was specified as.  We only do this if there is
only one correct choices value that could have been specified.  In the
follow_redirects example, a value of "True" only maps back to "yes" and
a value of "False" only maps back to "no" so we can do this.  If choices
also contained "on" and "off" then we couldn't map back safely and would
need to force the module author to change the module to handle this
case.

Fixes parts of the following PRs:

* https://github.com/ansible/ansible-modules-core/pull/4220
* https://github.com/ansible/ansible-modules-extras/pull/2593
9 years ago
Brian Coca 98c149859a added y/n to list of module booleans 9 years ago
Brian Coca 123d54e736 added pid to backup file name to avoid collisions 9 years ago
Ryan S. Brown bed24689ec Fix syntax error in json/jsonarg type parser
The lack of a comma caused the statement to always evaluate as a
`TypeError` when python interpreted `value (list, tuple, dict)` to call
value with the arguments list, tuple, and dict.
9 years ago
Brian Coca 92870ee996 jsonarg bikeshed to json, arg type implies 'arg' 9 years ago
Toshio Kuratomi 48a2773463 Find places where ziploader is used and change them to ansiballz so that people aren't confused when they google for information.information (#16715) 10 years ago
Brian Coca 0a439df4b0 removed redundant True/False cause `arg.lower()` 10 years ago
James Cammarata 3ea3fa8d46 Merge pull request #14639 from ivovangeel/find_mount_point-bug
Fixed bug in find_mount_point function
10 years ago
Toshio Kuratomi c4838286ac Make sure we don't end up with an empty PYTHONPATH (#16240)
When the PYTHONPATH is an empty string python will treat it as though
the cwd is in the PYTHONPATH.  This can be undesirable.  So make sure we
delete PYTHONPATH from the environment altgether in this case.

Fixes #16195
10 years ago
Toshio Kuratomi 0e98ce11c4 Comment on is_executable's limitations and change logic to only use bit-manipulations
This is clearer to anyone who understands that unix file modes are bitfields.
10 years ago
Dag Wieers 04ce71b4bd Give a module the possibility to known its own name (#16087)
* Give a module the possibility to known its own name

This is useful for logging and reporting and fixes the longstanding problem with syslog-messages:

    May 30 15:50:11 moria ansible-<stdin>: Invoked with ...

now becomes:

    Jun  1 17:32:03 moria ansible-copy: Invoked with ...

This fixes #15830

* Rename the internal name from module.ansible_module_name to module._name
10 years ago
Toshio Kuratomi 5a3493be5f Port urls.py to python3 and other byte vs text fixes (#16124)
* Port urls.py to python3

Fixes (largely normalizing byte vs text strings) for python3

* Rework what we do with attributes that aren't set already.

* Comments
10 years ago
Chris St. Pierre bfd69a7042 Modules: check for list-like choices in arg spec
This makes it possible to use anything other than a list (e.g., a
tuple, or dict.keys() in py3k) for argument_spec choices. It also
improves the error messages if you don't use a list type.
10 years ago
Toshio Kuratomi 3b69ef7e8b Add strings 'True' and 'False' as booleans as python bools converted to strings will look that way.
Workaround for custom modules which are using choices=BOOLEANS instead
of type='bool'.
10 years ago
Michael Scherer cf44db58e0 Add SEQUENCETYPE to handle the dict_keys type (#15953)
On python 3, there is a specific type for dict keys
instead of list, so previous tests based on Sequence didn't
not work anymore.
10 years ago
Toshio Kuratomi aad9f43dda Make load_params into a function that custom modules can access (#15913) 10 years ago
Toshio Kuratomi 61f2147385 Rename pycompat to pycompat24
This change makes it so we know when it is safe to get rid of the module
(when we stop supporting python2.4) and makes it easier for us to find
code that is using the functions in there to update.

If needed, we'll create a pycompat26 and pycompat27 as well.  These
files are for functions that are needed on that python version to write
portable code.  So python-2.4 compatible modules may need code in
pycompat24, python26+ modules may need code in pycompat26, etc.  If
a function is needed in multiple python versions, we should implement it
in an internal common file and use import to put it in the namespace for
each pycompatXY module.
10 years ago
Toshio Kuratomi 0cb05d8ac9 Some Python-3 module_utils support 10 years ago
Toshio Kuratomi 186337db28 Ship constants to the modules via internal module params rather than a secondary dict. 10 years ago
Matt Martz 1cee3f35b1 Guard against a shell profile printing extraneous data 10 years ago
Toshio Kuratomi 99e3880181 small python3 fix so that ping will run on python3 10 years ago
Toshio Kuratomi 409bfe4d0f Strip leading and trailing whitespace for json arg types 10 years ago
Toshio Kuratomi 3f104dcee9 Add a jsonarg type to arg spec (#15701)
This makes sure that if we get a list or dict that it is turned into
a jsonified string.
10 years ago
jctanner eb31faa7f5 Remove the ziploader provided pythonpaths from the env inside run_com… (#15674)
Remove the ziploader provided pythonpaths from the env inside run_command.

Fixes #15655
10 years ago
Toshio Kuratomi 487e6562ca Fix ziploader for the cornercase of ansible invoking ansible.
* Make ziploader's ansible and ansible.module_utils libraries into
  namespace packages.
* Move __version__ and __author__ from ansible/__init__ to
  ansible/release.py.  This is because namespace packages only load one
  __init__.py.  If that is not the __init__.py with the author and
  version info then those won't be available.
* In ziplaoder, move the version ito ANSIBLE_CONSTANTS.
* Change PluginLoader to properly construct the path to the plugins even
  when namespace packages are present.
10 years ago
Toshio Kuratomi 44e21f7062 Allow AnsibleModules to be instantiated more than once in a module
Fix SELINUX monkeypatch in test_basic
10 years ago
Yannig Perre 72f17f3ff3 New get_all_subclasses function in basic modules and use it in fact modules. 10 years ago
Toshio Kuratomi 7b5d2d3bec Make sure that args are interpreted as utf8 on python3 10 years ago
nitzmahone 5b336832af add _load_params debug overrides for module args/file passed on cmdline
Updated python module wrapper explode method to drop 'args' file next to module.
Both execute() and excommunicate() debug methods now pass the module args via file to enable debuggers that are picky about stdin.
Updated unit tests to use a context manager for masking/restoring default streams and argv.
10 years ago
Toshio Kuratomi 55bb24fb7d Reenable unicode=>byte conversion for module parameters to fix integration tests 10 years ago
Toshio Kuratomi 75546678d9 Fix unittests 10 years ago
Toshio Kuratomi b571ecdfec Move module arg passing from the environment to stdin (from the wrapper to the module) 10 years ago
Nathaniel Case dbc49ad95b First implementation of 'fallback' parameter
Implemented & documented for EOS & NXOS
10 years ago
Toshio Kuratomi a57a32adcc Revert "Make the 'path' param type also use abspath on the value"
This reverts commit 1ffadbcc80.

Some modules seem to have path listed for things that are "commands"  --
something that may be a path to a command or a bare command that should
be looked up in PATH.  With this change, if they were formerly looked up
inPATH they are now being made into an absolute path in the cwd.
Reverting this until we can think more about whether to do this and
change those modules to not use path for those parameters.
10 years ago
James Cammarata 1ffadbcc80 Make the 'path' param type also use abspath on the value 10 years ago
Toshio Kuratomi 4b0aa1214c Ziploader
* Ziploader proof of concept (jimi-c)

* Cleanups to proof of concept ziploader branch:

* python3 compatible base64 encoding
* zipfile compression (still need to enable toggling this off for
  systems without zlib support in python)
* Allow non-wildcard imports (still need to make this recusrsive so that
  we can have module_utils code that imports other module_utils code.)
* Better tracebacks: module filename is kept and module_utils directory
  is kept so that tracebacks show the real filenames that the errors
  appear in.

* Make sure we import modules that are used into the module_utils files that they are used in.

* Set ansible version in a more pythonic way for ziploader than we were doing in module replacer

* Make it possible to set the module compression as an inventory var

This may be necessary on systems where python has been compiled without
zlib compression.

* Refactoring of module_common code:

* module replacer only replaces values that make sense for that type of
  file (example: don't attempt to replace python imports if we're in
  a powershell module).
* Implement configurable shebang support for ziploader wrapper
* Implement client-side constants (for SELINUX_SPECIAL_FS and SYSLOG)
  via environment variable.
* Remove strip_comments param as we're never going to use it (ruins line
  numbering)

* Don't repeat ourselves about detecting REPLACER

* Add an easy way to debug

* Port test-module to the ziploader-aware modify_module()

* strip comments and blank lines from the wrapper so we send less over the wire.

* Comments cleanup

* Remember to output write the module line itself in powershell modules

* for line in lines strips the newlines so we have to add them back in
10 years ago
Nathaniel Case e4e913b331 Override params from environment variables, if set.
Fix a typo while I'm in the area.

Handle having None set in module.params more intelligently
10 years ago
Brian Coca fdb56e4bad avoid bad path entries 10 years ago
Toshio Kuratomi 917da92e2b Get rid of extra trailing space in log messages 10 years ago
Matthew Gamble 197e590d7c Small comment improvement in AnsibleModule class 10 years ago
James Cammarata 0e68c6d6fe Cleaning up use of literal_eval in basic.py AnsibleModule.safe_eval 10 years ago
Brian Coca 62ac5c047e clarified message 10 years ago
Brian Coca 8867d73420 reject extraneous data passed to mode
strictly permissions are allowed, file type info should not be passed in
alternate fixes #14771
10 years ago
James Cammarata 9acb5aa176 Changing location of reduce import to not use six.moves 10 years ago
James Cammarata b559d0e6ee Adding py3 stub for reduce from six.moves 10 years ago
James Cammarata e011f52557 Expanding unit tests for module_utils/basic.py 10 years ago
ivovangeel 23349911f1 Fixed bug in find_mount_point function
The find_mount_point function does not resolve the mount point of paths with a soft-link correctly and returns the wrong mount-point.

I have mounted an NFS filesystem on /nfs-mount. This directory contains a directory called "directory". I also created a soft-link to this last directory: /soft-link-to-directory -> /nfs-mount/directory. I created the following task to copy a file into /soft-link-to-directory:

    - name: copy file to nfs-mount
      copy:
        src: "file"
        dest: "/soft-link-to-directory/file"

This throws an exception:

invalid selinux context: [Errno 95] Operation not supported

This is caused by the find_mount_point function to return '/' as the mount point for '/soft-link-to-directory/file'. This should have been /nfs-mount. Because the find_mount_point returns the wrong mount-point, the is_special_selinux_path function does not recognise the file is on an NFS mount and tries to set the default SELinux context (system_u:object_r:default_t:s0), which fails. The context should have been: system_u:object_r:nfs_t:s0

Full Ansible output:

TASK [copy file to nfs-mount] **************************************************
fatal: [hostname]: FAILED! => {"changed": false, "checksum": "f34b60930a5d6d689cf49a4c16bd7f9806be608c", "cur_context": ["system_u", "object_r", "nfs_t", "s0"], "failed": true, "gid": 24170, "group": "foundation", "input_was": ["system_u", "object_r", "default_t", "s0"], "mode": "0644", "msg": "invalid selinux context: [Errno 95] Operation not supported", "new_context": ["system_u", "object_r", "default_t", "s0"], "owner": "root", "path": "/soft-link-to-directory/.ansible_tmpWCT6Z4file", "secontext": "system_u:object_r:nfs_t:s0", "size": 37, "state": "file", "uid": 0}
10 years ago
Brian Coca bc41f46fec pushed non-atomic to option of last resort
try to copy into place first
10 years ago
Pascal Grange 5d49f4e629 Fix related to #13981
When working around "bad systems that insist on not allowing
updates in an atomic manner", we should not run previous exception
management code that tries to perform atomic move in case of
exception since the dirty non atomic move has already been
performed.
10 years ago
Toshio Kuratomi 6276585882 Module params should default to str in most cases. 10 years ago
Brian Coca f50b381dba Merge pull request #13678 from Etherdaemon/fix_datetime_objects
fix for datetime exception in ecs_tasks
10 years ago
Toshio Kuratomi 1aaf5a399c Merge pull request #14317 from resmo/feature/fail_on_missing_params
module_utils/basic: add generic method for checking for missing param…
10 years ago
Toshio Kuratomi d1c2d16706 Allow setting run_command environment overrides for the life of an AnsibleModule 10 years ago
Brian Coca ad37a91514 really only want to prevent None typep here
false is sometimes needed
10 years ago
Brian Coca 5679b5414c avoid errors from possible None/False args 10 years ago
Rene Moser 11522b22c3 module_utils/basic: add generic method for checking for missing params when argspec can not be used. 10 years ago
Brian Coca 89c57666c3 fixed py3 compatibility 10 years ago
Brian Coca 70ac47ae61 allow atomic_move to not be atomic ...
just 'cause people build bad systems that insist on not allowing
updates in an atomic manner and force us to do them in a very
unsafe way that has race conditions and can lead to many issues.

if using this option you should really be opening a bug report with
the system that only allows for this type of update.

and now i shower though i doubt i'll feel clean
10 years ago
Brian Coca 6a62ad6c4b hide internal params once used 10 years ago
James Cammarata 0c237c4531 Merge pull request #14191 from paulcalabro/devel
Added hyphen (-) as a valid character for permissions
10 years ago
Paul Calabro 901d349f45 Adding a hyphen in the perms pattern section, since doing something like
go=- is a quick way to strip all permissions for non-owners.
10 years ago
Toshio Kuratomi 3cf59d30f7 For synchronize, fix sudo to execute on the remote end of the connection
* In 2.0.0.x become was reversed for synchronize. It was happening on
  the local machine instead of the remote machine. This restores the
  ansible-1.9.x behaviour of doing become on the remote machine.
  However, there's aspects of this that are hacky (no hackier than
  ansible-1.9 but not using 2.0 features).  The big problem is that it
  does not understand any become method except sudo.  I'm willing to use
  a partial fix now because we don't want people to get used to the
  reversed semantics in their playbooks.
* synchronize copying to the wrong host when inventory_hostname is
  localhost
* Fix problem with unicode arguments (first seen as a bug on synchronize)

Fixes #14041
Fixes #13825
10 years ago
Toshio Kuratomi a68d90a71a rework run_command's env setting to not change os.environ for the rest of the module.
New param to run_command to modify the environment for just this invocation.
Documentation and comment adjustments.
10 years ago
Brian Coca a56c0bc27b module invocation info depends on verbosity
since we were removing it on display, this saves us even transmiting it back
10 years ago
Brian Coca 5760f0effb dont error out on new internal vars 10 years ago
Brian Coca 477d632118 now file mode diff shows octal values 10 years ago
Brian Coca 6f2f7a79b3 add support for diff in file settings
this allows modules to report on what specifically changed when using
common file functions
10 years ago
Etherdaemon 0b92abaf67 Proposed fix for ansible/ansible-modules-extras#1348 due to datetime.datetime type not being matched 10 years ago
Brian Coca 9a118ce213 Merge pull request #13648 from bcoca/fix_invocation_and_moderrors
better module error handling
10 years ago
Michael Scherer 42b9a206ad Fix last commit, make it python3 compatible (and py24) 10 years ago
Brian Coca 957b376f9e better module error handling
* now module errors clearly state msg=MODULE FAILURE
* module's stdout and stderr go into module_stdout and module_stderr keys
which only appear during parsing failure
* invocation module_args are deleted from results provided by action
plugin as errors can keep us from overwriting and then disclosing info that
was meant to be kept hidden due to no_log
* fixed invocation module_args set by basic.py as it was creating different
keys as the invocation in action plugin base.
* results now merge
10 years ago
Brian Coca 010839aedc fix no_log disclosure when using aliases 10 years ago
Brian Coca 474772c81c Merge pull request #13639 from emonty/bool-conversion
Also convert ints to bool for type=bool
10 years ago
Monty Taylor c60749c922 Also convert ints to bool for type=bool 10 years ago
Toshio Kuratomi d32a885e98 Make return invocation information so that our sanitized copy will take precedence over what the executor knows. 10 years ago
Toshio Kuratomi c8fd599e14 Merge pull request #13373 from no2a/boolean
BOOLEAN should contain boolean literals
10 years ago
Toshio Kuratomi 9b81c35d06 Don't compare or merge str with unicode
Fixes #13387
10 years ago
Arata Notsu 6d6d4f0c8e BOOLEAN should contain boolean literals
It is natural that an argument_spec with choises=BOOLEAN accepts
boolean literal (True, False) though the current implementation
allows only string or int.
10 years ago
Toshio Kuratomi e2ddc2f6ab Call the function :-)
Fixes #13330
10 years ago
James Cammarata 0e447e3f41 Merge branch 'devel' of https://github.com/mathieumd/ansible into mathieumd-devel 10 years ago
Toshio Kuratomi 6e5055e786 Update the use of no_log values to cover everything that heuristic_log_sanitize does.
Fixes #12792
10 years ago
Toshio Kuratomi c2d188baff Hide values in json returns which were given in parameters marked no_log. 10 years ago
Mathieu 260a3e5ce7 Fixes #11055 - Set locale via LC_ALL 10 years ago
Brian Coca c57200925f made syslog import optional as intel's edison custom compiles python w/o it 10 years ago
Toshio Kuratomi 15d7f53846 AnsibleModules.log() fix for python3
Also add unittests for AnsibleModules.log()

Fixes #12586
10 years ago
Brian Coca 1a56a5c442 created debug method, renamed debug attribute to _debug 10 years ago
Marius Gedminas cc1e1648f5 Tweak comment style 10 years ago
Marius Gedminas 213029a21e Python 3: don't convert unicode to unicode 10 years ago
Marius Gedminas c7be004c19 Python 3 has no dict.iteritems()
(Reminder: cannot use six here, module_utils get shipped to remote
machines that may not have six installed -- besides six doens't support
Python 2.4.)
10 years ago
Marius Gedminas 9f3e5ceb14 Make sure 'basestring', 'bytes' and 'unicode' are defined
Python 3 doesn't have 'basestring' and 'unicode'.

Python 2.4 doesn't have 'bytes'
10 years ago
Brian Coca 37a918438b task logging revamp
* allow global no_log setting, no need to set at play or task level, but can be overriden by them
 * allow turning off syslog only on task execution from target host (manage_syslog), overlaps with no_log functionality
 * created log function for task modules to use, now we can remove all syslog references, will use systemd journal if present
 * added debug flag to modules, so they can make it call new log function conditionally
 * added debug logging in module's run_command
10 years ago
Toshio Kuratomi dcdcd9e9c5 Move is_executable to the toplevel of basic.py so we can utilize it from other code 10 years ago
Marius Gedminas 2c4982b58d Python 3: there's no itertools.imap
Because the builtin map() acts like an iterator already.
10 years ago
Marius Gedminas 6708d56a21 Python 3: avoid long integer literals
Even Python 2.4 automatically promotes int to long.
10 years ago
Marius Gedminas f5d4935197 Python 3: treat python as a function in module_utils/basic.py
NB: we can't use 'from __future__ import print_function', but luckily
print(one_thing) works fine on both Python 2 and Python 3 without that.
10 years ago
Marius Gedminas e71a986e16 Python 3: avoid octal constants in module_utils/basic.py 10 years ago
Marius Gedminas d2bec7f81f Python 3: avoid "except ..., e:" in module_utils/basic.py
Make the code compatible with Pythons 2.4 through 3.5 by using
sys.exc_info()[1] instead.

This is necessary but not sufficient for Python 3 compatibility.
10 years ago
Toshio Kuratomi 00b1a2c865 Restore ValueError in md5 method and change finding the available hash algorithms so we only have to do it once 10 years ago
muffl0n 8d6d711a5c move get_available_hash_algorithms() from get_url 10 years ago
Toshio Kuratomi 6a68be4e28 Handle quoting of values in dict parameters 11 years ago
Toshio Kuratomi ddec06ccfe Detect the old python-json library
Fixes #11654
11 years ago
Brian Coca 4f98fac494 Merge pull request #10914 from bcoca/non_posix_file_copy_fix
hack to prevent tempalte/copy errors on vagrant synced folders
11 years ago
Toshio Kuratomi dd058a1dc2 Fix required_if (needed to pass list to _count_terms) 11 years ago
Brian Coca 2c9d1257ba put type checking before looking against choices array to always get type comparrison correctly 11 years ago
James Cammarata cf51d0a790 Fixing up some check-mode stuff 11 years ago
Toshio Kuratomi be6db1a730 Refactor the argspec type checking and add path as a type 11 years ago
Toshio Kuratomi 160e71e2cf Some flake8 cleanup 11 years ago
Dag Wieers 4ca4d36ae6 Change syslog (priority) level from LOG_NOTICE to LOG_INFO
If you look at the meaning of the different syslog levels, NOTICE means that the event may need someone to look at it. Whereas INFO is pure informational.

Since module invocations are in fact requested (deliberate) actions, they shouldn't need any additional post-processing, and therefore should not be logged as NOTICE.

This may seem like hairsplitting, but correctly categorizing system events helps weeding through the noise downhill.

According to Wikipedia: https://en.wikipedia.org/wiki/Syslog

5 	Notice 		notice 	Events that are unusual but not error conditions .
6 	Informational 	info 		Normal operational messages -no action required. Example an application has started, paused or ended successfully.
11 years ago
James Cammarata fe41f109a9 Merge branch 'v2_final' into devel_switch_v2 11 years ago
James Cammarata 4bc7703db3 Fixing some small bugs related to integration tests (v2) 11 years ago
James Cammarata 2bad888f28 Merge branch 'v2_final' into devel_switch_v2
Conflicts:
	lib/ansible/inventory/__init__.py
	lib/ansible/modules/core
	lib/ansible/utils/__init__.py
	lib/ansible/utils/module_docs.py
11 years ago
James Cammarata e59d4f3b51 More module_utils/basic.py unit tests for v2 11 years ago
James Cammarata 339a02c384 Started reworking module_utils/basic unit tests (v2) 11 years ago
Toshio Kuratomi d793ed360b Fix syntaxerror in the required_if arg spec check 11 years ago
Toshio Kuratomi 0f23d8a503 Fix syntaxerror in the required_if arg spec check 11 years ago
Monty Taylor 31609e1b16 Add required_if to AnsibleModule
There is a common pattern in modules where some parameters are required
only if another parameter is present AND set to a particular value. For
instance, if a cloud server state is "present" it's important to
indicate the image to be used, but if it's "absent", the image that was
used to launch it is not necessary. Provide a check that takes as an
input a list of 3-element tuples containing parameter to depend on, the
value it should be set to, and a list of parameters which are required
if the required parameter is set to the required value.
11 years ago
Toshio Kuratomi c6b286424f Merge pull request #9423 from emonty/features/required-if
Add required_if to AnsibleModule
11 years ago
Brian Coca 16c70dd7d4 added equivalent of #9636 to v2 11 years ago
Brian Coca 6000db7e5d Merge pull request #9636 from Batmat/fix-message-i18n-parsing-error
Setting LC_MESSAGES: prevent unparseable messages (fixes issue #9635)
11 years ago
Toshio Kuratomi bb81f025b0 Merge pull request #8679 from j0057/support-arch-8653
Add support for Arch to module_utils.basic.py
11 years ago
Rene Moser 8da580a29c basic: fix ValueError if value of a type='int' is not an int
With this fix, we get a friendly error message:

    failed: [localhost] => {"failed": true}
    msg: value of argument start_port is not of type int and we were unable to automatically convert
11 years ago
Rene Moser 8f29ca23ae basic: fix ValueError if value of a type='int' is not an int
With this fix, we get a friendly error message:

    failed: [localhost] => {"failed": true}
    msg: value of argument start_port is not of type int and we were unable to automatically convert
11 years ago
Brian Coca 0913b8263c made special treatment of certain filesystem for selinux configurable 11 years ago
Brian Coca e2de336a23 made special treatment of certain filesystem for selinux configurable 11 years ago
Brian Coca 483c61414e added missing : 11 years ago
Brian Coca 013c4631e3 hack to prevent tempalte/copy errors on vagrant synced folders that report incorrectly errno 26
fixes #9526
11 years ago
James Cammarata ce3ef7f4c1 Making the switch to v2 11 years ago
Brian Coca faadb68308 backup_local now only tries to back up exising files, returns '' otherwise 11 years ago
Joost Molenaar e79c920260 Add support for Arch to module_utils.basic.py
Fixes ansible/ansible#8653
11 years ago
Brian Coca 1fa3dbb7d2 capture IOErrors on backup_local (happens on non posix filesystems)
fixes #10591
11 years ago
Toshio Kuratomi aaa25eb75c Make run_command() work when we get byte str with non-ascii characters (instead of unicode type like we were expecting)
Fix and test.

Fixes #10536
11 years ago
Brian Coca 942ff8d0b9 Merge pull request #10035 from phenomenes/fix_9911
Adds seconds to backup timestamp
11 years ago
Stratos Moros 6caeded74e Fix umask calculation on file creation. Fixes #10257 11 years ago
Toshio Kuratomi c9fb97cc86 Be careful not to set the permissions of the destination of a symlink.
It's up to the module using the set_fs_attributes*/set_mode* methods to
specify the filename of the destination of the symlink if that's really
the file that should be modified.

Half of the fix for:
https://github.com/ansible/ansible-modules-core/issues/778
11 years ago
Toshio Kuratomi 4902c06304 Obfuscate passwords in more places where it is displayed 11 years ago
Toshio Kuratomi 915d232d5f jinja2 cannot handle byte strs with non-ascii. So we need to transform potential byte str into unicode type. This fix is for dynamic inventory.
Fixes #10007
11 years ago
Jimena Cabrera-Notari 1e865368ac Adds seconds to backup timestamp 11 years ago
Luke Macken dea0ee663f Use send instead of sendv on the systemd.journal (fixes #9886) 11 years ago
Baptiste Mathus a1adff4ff0 Setting LC_MESSAGES: prevent unparseable messages
This locale variable defines how tools should display their messages.
This is for example gonna change the yum message from "Nothing to do" to
"Rien a faire" in my case (french).

As the yum module parses that string in err, if the message is not
enforced in english this is gonna fail.

So this commits just enriches a bit more the code that's already written
for that enforcement.

This commit fixes issue #9635.
11 years ago
James Cammarata 5bc81f9ae7 Add ability to detect prompts in stdout from run_command 11 years ago
Toshio Kuratomi 9a7eb57718 Some changes to FIPS compat since SLES implements it differently 11 years ago
Toshio Kuratomi 6a85f3ebc7 Add comments/docstrings not to use md5 unless forced to by forces outside our control. 11 years ago
Toshio Kuratomi f1267c0b05 Move from md5 to sha1 to work on fips-140 enabled systems 11 years ago
Monty Taylor 61ae3c732f Add required_if to AnsibleModule
There is a common pattern in modules where some parameters are required
only if another parameter is present AND set to a particular value. For
instance, if a cloud server state is "present" it's important to
indicate the image to be used, but if it's "absent", the image that was
used to launch it is not necessary. Provide a check that takes as an
input a list of 3-element tuples containing parameter to depend on, the
value it should be set to, and a list of parameters which are required
if the required parameter is set to the required value.
11 years ago
Toshio Kuratomi a10d10f647 Workaround more python-2.6 shlex not being able to handle unicode strings 11 years ago
James Cammarata b376e208c7 Adding "follow" param for file/copy options
Also modifies the template action plugin to use this new param
when executing the file/copy modules for templating so that links
are preserved correctly.

Fixes #8998
11 years ago
Toshio Kuratomi 8233522a7a Reduce commenting as basic.py is copied to the remote host with every module transfer.
Move some comments to the unittest as we might look at that if we decide
to refactor the code.
11 years ago
Toshio Kuratomi 1afc8161a1 New password obfuscation in syslog messages that:
* makes speed acceptable for some datasets
* obfuscates multiple detected passwords
* obfuscates more characters to account for some corner cases when
  trying to detect passwords.

Fixes #8364
11 years ago
Toshio Kuratomi 4f55bcc298 Standardize on bytes internally to _log_invocation 11 years ago
Matt Martz 2b307985bc Don't use ternary if statements. Fixes #8784 11 years ago
James Cammarata c21c66c740 Merge branch 'file_symbolic_mode' of https://github.com/pbitty/ansible into pbitty-file_symbolic_mode 11 years ago
James Cammarata 24c4277479 Remove tabs added from 677de07 11 years ago
James Cammarata 5e240fec71 Merge branch 'devel' of https://github.com/l1k/ansible into l1k-devel
Conflicts:
	test/integration/roles/test_copy/tasks/main.yml
11 years ago
James Cammarata 3a7aca6066 Fix no_log value for content in common file args settings
Also adds a test to ensure the content value is not logged.

Related to #8647
11 years ago
Lukas Wunner 677de07f44 Try optimistic chown, do not error out if not permitted to chown
Add unit test
11 years ago
James Cammarata 8dafacd4e9 Make env param a dict type instead of list
Also modifies param type checking code to remove whitespace from
around params before splitting them into k=v pairs.

Fixes #8199
11 years ago
James Cammarata 600a4657b4 Catch error in atomic_move when creating temporary file
Fixes #8480
11 years ago
Lukas Wunner f4053fcf3a Only chown on atomic move if invoked as root
Linux and BSD derivatives do not allow unprivileged users to
"give away" files to others for security reasons. (System V
derivatives allow that but they're rare nowadays.)
11 years ago
Michael DeHaan d0205b2878 Merge pull request #8500 from sivel/rax-de-dupe
rax: Move additional shared code into module utils
11 years ago
Michael DeHaan 8c4161d4a1 Merge branch 'retf_py' of git://github.com/berendt/ansible into devel
Conflicts:
	lib/ansible/inventory/vars_plugins/group_vars.py
	plugins/callbacks/mail.py
11 years ago
Bekim Berisha 5272e1099d Keep docstring up to date with the code in basic module 11 years ago
Matt Martz 88acb48753 Add ANSIBLE_VERSION to module_utils/basic.py and manipulate the pyrax user-agent 11 years ago
James Cammarata 5d0bb33ede Make run_command process communication smarter
The run_command module function will now poll stdout/stderr for
data rather than using the builtin command communicate(), which can
hang under certain circumstances.

Fixes #7452
Fixes #7748
Fixes #8163
11 years ago
Michael DeHaan 645ab7baff Merge pull request #7950 from mesk41in/devel
Fix unsupported regexp parameter in assemble
12 years ago
Michael DeHaan fb60e767a7 Taking alternate approach.
Revert "Fix hostname when get_distribution_version() returns a string."

This reverts commit 08f97c0b9d.
12 years ago