Commit Graph

142 Commits (97cc0cce7f53b704f8541530e42d5e515584cd95)

Author SHA1 Message Date
Matt Martz ad0827e5c0
When using ANSIBLE_JINJA2_NATIVE bypass our None filtering in _finalze (#41408)
* When using ANSIBLE_JINJA2_NATIVE bypass our None filtering in _finalize. Fixes #41392

* Add tests for _finalize bypass

* Address python3 failures in tests
6 years ago
jctanner a9e53cdb68 Allow config to enable native jinja types (#32738)
Co-authored-by: Martin Krizek <martin.krizek@gmail.com>
6 years ago
Toshio Kuratomi 81b2529159 Fix when template paths contain non-ascii chars and using the path in ansible_managed
Fixes #27262
6 years ago
Brian Coca 135ec86eb5 fix exception on lookup ignore error
no log, so only_log ...
6 years ago
Victor Bocharsky a30befa609 Remove duplicated "instead" word (#38800)
* Remove duplicated "instead" word

* Actually fix the message
6 years ago
Brian Coca d78da403b6
allow user control of lookup error behaviour (#35932)
* allow user control of lookup error behaviour

this does not affect undefined vars, only other exceptions raised by a lookup

i.e lookup('file' ..) not finding a file
6 years ago
Brian Coca 5a333859fe allow for parameterized string functions
now also allow for ending parens

from following, 1, 2, 4 and 5 match, rest are ignored.

	{doc | to_nice_json}}
	{{(doc | to_nice_json)}}
	{{doc | to_nice_json| from_json}}
	{{doc | to_nice_json()}}
	{{doc | to_nice_json(indent=2)}}
	{{doc | to_nice_json(indent=2) | from_json()}}
	{{doc | to_nice_json(indent=2) | from_json}}

fixes #37579
6 years ago
Matt Martz 1f824bd620 Don't overwrite builtin jinja2 filters with tests (#37881)
* Don't overwrite builtin jinja2 filters with tests. Fixes #37856

* Fix tests and other callers of _get_filters
6 years ago
Toshio Kuratomi 0633f73faf Fix loader for filters (#37748)
* Fix loading of filter and test plugins

Filter and test plugins are different than other plugins in that they
can have many plugins in a single file.  Therefore they need to operate
a little differently.  They need to have all of the potential files
returned.  Then the caller takes care of passing those onto jinja2 in
order for jinja2 to make use of them.

This problem was (most recently) introduced with f921369445

This commit also restructures how we deduplicate plugins to take paths
into account.  If we want to start scoping which set of modules are
loaded (due to roles, for instance) we'll need to hang on to the path
information.

* add integration test for override

* Fix style checks for bcoca code

* Implement jinja2 plugin loader as a subclass

Having a subclass allows us to customize the overriding of jinja
plugins.  We can then move common parts of common code into the Loader.
6 years ago
Toshio Kuratomi 03a6d72633 Revert "remove query/q (#36315)"
This reverts commit b47d2e07e1.

query is a feature for 2.5.  We're not reverting it now.
6 years ago
Brian Coca b47d2e07e1
remove query/q (#36315)
* remove query/q

remove and fixed tests for removed func

* paren fix
6 years ago
Andrew Gaffney dae737c8b7 Only template each hostvars var on-demand (fixes #33259) 6 years ago
Martin Krizek 63fdc3f08f
Fix jinja2>=2.9 nested include vars (#35099)
This fixes a bug when parent's local vars where not available in nested
includes. The bug can only be seen with jinja>=2.9 which changes
how the variable scopes work.

Fixes #34886
6 years ago
Pilou d608eb9530 Check that AnsibleUndefinedVariable doesn't occur when an unused variable references an undefined variable (#35571)
* Check that AnsibleUndefinedVariable doesn't occur

* AnsibleUndefinedVariable exc.: don't modify type
6 years ago
Toshio Kuratomi 3d614bfe84 Clarify lookup plugin TypeError recovery
Change the code and comments around recovering from a TypeError in
handling the return value from lookup plugins to make it clearer what
we're recovering from.
6 years ago
Thomas Quinot 101e983f07 Remove incorrect assumption on exception constructors (#35271)
Do not assume that all exception constructors accept a single string
argument. For example UnicodeError's __init__ takes 5 parameters:
encoding, object, start, end, reason.

Also, if e.message is present but empty, fall back on stringifying
the exception occurrence.

Fixes #35270
7 years ago
Sloane Hertel 7bc754674c
[template/vars] Use to_native(exception) as a fallback for Python 3 which doesn't have a .message attribute (#34044) 7 years ago
Brian Coca 67c83823f2 Add q/query aliases to lookup (#33466)
* Add L alias to lookup, defaults to real list
* renamed to q/query as per core meeting
* also force wantlist=true
7 years ago
Matt Martz 4fe08441be Deprecate tests used as filters (#32361)
* Warn on tests used as filters

* Update docs, add aliases for tests that fit more gramatically with test syntax

* Fix rst formatting

* Add successful filter, alias of success

* Remove renamed_deprecation, it was overkill

* Make directory alias for is_dir

* Update tests to use proper jinja test syntax

* Update additional documentation, living outside of YAML files, to reflect proper jinja test syntax

* Add conversion script, porting guide updates, and changelog updates

* Update newly added uses of tests as filters

* No underscore variable

* Convert recent tests as filter changes to win_stat

* Fix some changes related to rebasing a few integration tests

* Make tests_as_filters_warning explicitly accept the name of the test, instead of inferring the name

* Add test for tests_as_filters_warning

* Update tests as filters in newly added/modified tests

* Address recent changes to several integration tests

* Address recent changes in cs_vpc
7 years ago
Matt Martz 99d4f5bab4 Remove uses of assert in production code (#32079)
* Remove uses of assert in production code

* Fix assertion

* Add code smell test for assertions, currently limited to lib/ansible

* Fix assertion

* Add docs for no-assert

* Remove new assert from enos

* Fix assert in module_utils.connection
7 years ago
Brian Coca e010fcf7e1 added debug info when skipping undef 7 years ago
Matt Clay 68aeaa58a8 Fix dangerous default args. (#29839) 7 years ago
Brian Coca f921369445 Ansible Config part2 (#27448)
* Ansible Config part2

- made dump_me nicer, added note this is not prod
- moved internal key removal function to vars
- carry tracebacks in errors we can now show tracebacks for plugins on vvv
- show inventory plugin tracebacks on vvv
- minor fixes to cg groups plugin
- draft config from plugin docs
- made search path warning 'saner' (top level dirs only)
- correctly display config entries and others
- removed unneeded code
- commented out some conn plugin specific from base.yml
- also deprecated sudo/su
- updated ssh conn docs
- shared get option method for connection plugins
- note about needing eval for defaults
- tailored yaml ext
- updated strategy entry
- for connection pliugins, options load on plugin load
- allow for long types in definitions
- better display in ansible-doc
- cleaned up/updated source docs and base.yml
- added many descriptions
- deprecated include toggles as include is
- draft backwards compat get_config
- fixes to ansible-config, added --only-changed
- some code reoorg
- small license headers
- show default in doc type
- pushed module utils details to 5vs
- work w/o config file
- PEPE ATE!
- moved loader to it's own file
- fixed rhn_register test
- fixed boto requirement in make tests
- I ate Pepe
- fixed dynamic eval of defaults
- better doc code

skip ipaddr filter tests when missing netaddr
removed devnull string from config
better becoem resolution

* killed extra space with extreeme prejudice

cause its an affront against all that is holy that 2 spaces touch each other!

shippable timing out on some images, but merging as it passes most
7 years ago
Zac Medico 501fc7a248 template: fix KeyError: 'undefined variable: 0 (#27972)
* template: fix KeyError: 'undefined variable: 0

For compatibility with the Context.get_all() implementation
in jinja 2.9, make AnsibleJ2Vars implement collections.Mapping.
Also, make AnsibleJ2Template.newcontext() handle dict type
for the 'vars' parameter.

See: d67f0fd4cc
Fixes: https://github.com/ansible/ansible/issues/20494

* add units/template/test_vars

* intg tests for jinja-2.9 issues like 20494

test cases here are based on
https://github.com/ansible/ansible/issues/20494#issue-202108318
7 years ago
Adrian Likins 4befefd78c Try to show original exception info for yaml (and other) errors (#24468)
* show original exception for yaml (and other) errors

In places where we need to catch a yaml error and raise
an AnsibleError, add the orig yaml exc to the AnsibleError
via the orig_exc arg.

When the AnsibleError is displayed it will now include the
AnsibleError (AnsibleParserError for example) and the type
and message from the original yaml exception.

This provides more detail to the error messages related to
yaml errors.

This also improves errors from dataloader (for example,
previously if a wrong password was used for a vault encrypted
yaml file, the error was very vague and suggested yaml errors,
but now the message includes the original exception from vault
indicating the password was incorrect or missing).

Add a text note to playbook helper asserts. For playbook
syntax/layout errors that aren't yaml errors, but errors
indicating invalid data structures for a playbook/task/role/block,
we now include some info about where the assert was and
why it was raised.

In places we raise an AnsibleParserError in an except
clause, pass the original exception to AnsibleParserError via
orig_exc arg.

Make assorted error messages a little more specific (like
the playbook helper load methods)

* Revert "Include the original YAML error in syntax error messages"

This reverts commit 781bb44b02.
7 years ago
Dag Wieers 5553b20828 Collated PEP8 fixes (#25293)
- Make PEP8 compliant
7 years ago
Sergey Bondarev f39fa7fd22 fix from https://github.com/ansible/ansible/pull/23001 7 years ago
Sergey Bondarev 72fc9f5cbe fix deprecation import ansible.vars.unsafe_proxy to ansible.utils.unsafe_proxy 7 years ago
James Cammarata ed56f51f18 Fixing security issue with lookup returns not tainting the jinja2 environment
CVE-2017-7481

Lookup returns wrap the result in unsafe, however when used through the
standard templar engine, this does not result in the jinja2 environment being
marked as unsafe as a whole. This means the lookup result looses the unsafe
protection and may become simple unicode strings, which can result in bad
things being re-templated.

This also adds a global lookup param and cfg options for lookups to allow
unsafe returns, so users can force the previous (insecure) behavior.
7 years ago
Toshio Kuratomi 1c05ed7951 Fix circular import with unsafe_proxy, template, and vars
template/__init__.py imported unsafe_proxy from vars which caused
vars/__init__.py to load.  vars/__init__.py needed template/__init__.py
which caused issues.  Loading unsafe_proxy from another location fixes
that.
7 years ago
Brian Coca 31045d58c6 added versions to dep notices (#24019)
* added versions to dep notices

* pep7

* string
7 years ago
Brian Coca a108f0fcd3 avoid hosts 'pre templated warnings' (#23878)
* avoid hosts 'pre templated warnings'

fixed is_template failing on undefined
fixes #23057

* py3 compat
7 years ago
Brian Coca 4594bee65a keep unsafe .. unsafe (#23742)
* keep unsafe .. unsafe

fixes #23734, which was broken in previous fix that allowed non string types to be templated
use new 'is_template' function vs bastardizing others
refactored clean_data to allow for arbitrary data structures to clean
fixed/removed some tests

* deal with complex data for is_template

* typos
7 years ago
Brian Coca 5b7e8a7bd6 centralize ansible_managed and other template vars
now template lookup supports these again.
7 years ago
Dag Wieers ac43a1bbbc Windows: Use the correct newline sequence for the platform (#21846)
This change to the template action plugin make template use the
platform's native newline_sequence for Jinja.

We also added the option `newline_sequence` to change the newline
sequence using by Jinja if you need to use another newline sequence than
the platform default.

This was previously discussed in
https://github.com/ansible/ansible/issues/16255#issuecomment-278289414

And also relates to issue #21128
7 years ago
Toshio Kuratomi 2fff690caa Update module_utils.six to latest (#22855)
* Update module_utils.six to latest

We've been held back on the version of six we could use on the module
side to 1.4.x because of python-2.4 compatibility.  Now that our minimum
is Python-2.6, we can update to the latest version of six in
module_utils and get rid of the second copy in lib/ansible/compat.
7 years ago
Matt Martz 3164e8b561 E501 fixes (#22879) 7 years ago
James Cammarata 86beb55a90 Also clean template data even if marked unsafe
Fixes #20568
7 years ago
James Cammarata 0d418789a2 Revert "Fixing another corner case for security related to CVE-2016-9587"
This reverts commit bcceada5d9.
7 years ago
Adrian Likins df3e4cd7f4 Don't check for var._obj in template._clean_data (#20868)
* Don't check for var._obj in template._clean_data

AnsibleUnsafe or other unsafe vars used to have a
'_obj' slot but no longer do. This was causing attribute
errors if a object was 'unsafe' but not a string.

Add tests for AnsibleUnsafe, lookups, and AnsibleContext
7 years ago
Matt Clay cb76200c7d PEP 8 E111 & E114 cleanup. (#20838) 8 years ago
Matt Clay 10d9318de7 PEP 8 indent cleanup. (#20800)
* PEP 8 E121 cleanup.

* PEP 8 E126 cleanup.

* PEP 8 E122 cleanup.
8 years ago
James Cammarata 188c3c608a Don't restrict local jinja2 variables to those that start with l_
Per a change in jinja2 2.9, local variables no longer are prefixed
with l_, so this updates AnsibleJ2Vars to pull in all locals (while
excluding some) regardless of name.

Fixes #20063

(cherry picked from commit 4d49b317929b86e1fc1b0cbace825ff73b372dc7)
8 years ago
James Cammarata b7cdc21aee Additional security fixes for CVE-2016-9587 8 years ago
Brian Coca f078946ed3 no calls plz 8 years ago
James Cammarata a94a48f85f Partial revert of 76f7ce55 8 years ago
James Cammarata d316068831 Additional fixes for security related to CVE-2016-9587 8 years ago
Computest bcceada5d9 Fixing another corner case for security related to CVE-2016-9587 8 years ago
Toshio Kuratomi 80357e07de Add some comments about how we're cleaning callables 8 years ago
Toshio Kuratomi 027b126b42 Remove _clean_data_struct() advice as that was a 1.x design
data now goes through this extra cleaning in the template rather than
being an explicit other step.
8 years ago