Commit graph

39 commits

Author SHA1 Message Date
Martin Krizek
a2af8432f3
Local vars should have highest precedence in AnsibleJ2Vars ()
Ability to add local variables into AnsibleJ2Vars was added in
18a9eff11f to fix . Local variables
are added using ``AnsibleJ2Vars.add_locals()`` method when creating a
new context - typically when including/importing a template with
context. For that use case local template variables created using
``set`` should override variables from higher contexts - either from the
play or any parent template, or both; Jinja behaves the same way.

Also removes AnsibleJ2Vars.extras instance variable which is not used.

Also adds missing test for .

Fixes 
Fixes 

ci_complete
2021-01-26 11:37:56 +01:00
Martin Krizek
00b22ab55e
Provide more information in AnsibleUndefinedVariable ()
* Provide more information in AnsibleUndefinedVariable

Fixes 
2020-09-22 09:38:53 -04:00
Martin Krizek
bf7276a4e8
Emit proper error for x in y when y is undefined ()
Fixes 
2020-07-30 15:57:01 -04:00
Matt Clay
4816bb4f43
More boilerplate fixes. ()
* Fix boilerplate in hacking dir.
* Fix boilerplate in docs dir.
* Fix boilerplate in integration tests.
* Fix boilerplate in examples.
2020-06-22 19:05:30 -07:00
Martin Krizek
ff1ba39c8a
Prevent templating unused variables for {%include%} ()
Fixes 
2020-04-14 10:27:02 +02:00
Yanis Guenane
4fd2dce7f3
Testing: Add support for AIX platform () 2020-01-29 15:56:51 -08:00
Matt Clay
479845a05c
Expand Shippable test matrix. ()
* Add 2 CI groups for AWS.
* Add 1 CI group for vmware.
* Add 1 CI group for CS.
* Add 1 CI group for posix.
2020-01-29 14:43:27 -08:00
Matt Clay
0c74ee4352
Clean up various integration tests. ()
* Fix var_blending test temp dir usage.

* Fix filters integration test:

- Fix use of `output_dir`.
- Use `localhost` instead of `testhost` since we're only testing filters.
- Fix `fileglob` test to actually test a directory that exists.

* Fix lookups integration test:

- Fix use of `output_dir`.
- Use `localhost` instead of `testhost` since we're only testing lookups.

* Fix ansible-runner test temp dir usage.

* Fix template and template_jinja2_latest test.

Use the `OUTPUT_DIR` env var to get the output directory for the tests.

* Fix Python version compat in filters test.

* Skip filters test on Python 2.6.
2019-08-14 16:33:45 -07:00
Martin Krizek
b7868529ee
Revert "Speed up VariableManager by preserving Templar state. ()" ()
This reverts commit 6069d09b9d.

Fixes 
2019-07-22 10:27:11 +02:00
Brian Coca
b9b0b23015
safe_eval fix ()
* just dont pass locals

 - also fix globals
 - added tests

* fixed tests
2019-06-06 15:36:22 -04:00
Matt Martz
e89f8bae86
Extend jinja2 nested undefined support to keys/indices () 2019-04-10 10:35:31 -05:00
Abhijeet Kasurde
142732dba9 dataloader: check exact value of dir ()
Include path in role with directory which has 'tasks' as end.
For example, roles/sometasks/templates is now considered while searching path.

Fixes: 

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2019-03-16 01:48:01 -04:00
Jordan Borean
17bfc60423
test - add setup target that creates the nobody user ()
* test - add setup target that creates the nobody user

* do not set explicit gid/uid for nobody user

* Do no create group and only touch basic attributes
2019-02-22 14:04:10 +10:00
Abhijeet Kasurde
24d1886499
template: add additional variable for dest path ()
Signed-off-by: Dustin Spicuzza <dustin@virtualroadside.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2019-02-19 14:15:19 +05:30
Andrew Gaffney
9c35f18dd6 Custom jinja Undefined class for handling nested undefined attributes ()
This commit creates a custom Jinja2 Undefined class that returns
Undefined for any further accesses, rather than raising an exception
2019-02-12 15:04:00 -05:00
Adam Miller
6c61336a4b enable template target integration tests on rhel8 beta ()
Signed-off-by: Adam Miller <admiller@redhat.com>
2018-12-05 17:58:15 -05:00
Matt Clay
a41c0405a7
Add CI platform: rhel/8.0 () 2018-11-16 22:06:19 -08:00
Julien Champseix
19dc267e4c Allow specifying the output encoding in the template module ()
Allow specifying the source and destination files' encodings in the template module

* Added output_encoding to the template module, default to utf-8
* Added documentation for the new variables
* Leveraged the encoding argument on to_text() and to_bytes() to keep the implementation as simple as possible
* Added integration tests with files in utf-8 and windows-1252 encodings, testing all combinations
* fix bad smell test by excluding windows-1252 files from the utf8 checks
* fix bad smell test by excluding valid files from the smart quote test
2018-07-25 13:10:40 -07:00
Matt Clay
4e489d1be8
Update Shippable integration test groups. ()
* Update Shippable integration test groups.
* Update integration test group aliases.
* Rebalance AWS and Azure tests with extra group.
* Rebalance Windows tests with another group.
2018-07-23 20:46:22 -07:00
Toshio Kuratomi
81b2529159 Fix when template paths contain non-ascii chars and using the path in ansible_managed
Fixes 
2018-04-30 16:47:27 -07:00
Toshio Kuratomi
f91d961cb4 Add tests for template with non-ascii filenames
This is a test in response to  but I could not provoke the error
so it only shows that the current code is working with non-ascii
filenames in this case.  It doesn't show whether there's some other bug
somewhere.
2018-04-26 13:27:18 -07:00
Toshio Kuratomi
83c1cba511
Fixes for mode=preserve ()
* Fixes for mode=preserve

* Document mode=preserve for template and copy
* Make mode=preserve work with remote_src for copy
* Make mode=preserve work for template
* Integration tests for copy & template mode=preserve

Fixes 

* Changed mode option in win_copy to hidden option as it doesn't reflect copy mode
2018-04-26 07:14:37 -07:00
Alex Tsitsimpis
c3ab6cb9b1 template: Add option to lstrip_blocks' and fix settingtrim_blocks` inline ()
* template: Add integration tests for `lstrip_blocks'

Signed-off-by: Alex Tsitsimpis <alextsi@arrikto.com>

* template: Fix passing `trim_blocks' inline

Fix passing `trim_blocks' option to the template module as inline
argument. Previously passing the `trim_blocks' option inline instead of
using the YAML dictionary format resulted in it always being set to
`True', even if `trim_blocks=False' was used.

Signed-off-by: Alex Tsitsimpis <alextsi@arrikto.com>

* template: Add option to `lstrip_blocks'

Add option to set `lstrip_blocks' when using the template module to
render Jinja templates. The Jinja documentation suggests that
`trim_blocks' and `lstrip_blocks' is a great combination and the
template module already provides an option for `trim_blocks'.

Note that although `trim_blocks' in Ansible is enabled by default since
version 2.4, in order to avoid breaking things keep `lstrip_blocks'
disabled by default. Maybe in a future version it could be enabled by
default.

This seems to address issue  in a more appropriate way than the
suggested.

Signed-off-by: Alex Tsitsimpis <alextsi@arrikto.com>

* template: Add integration tests for `trim_blocks'

Signed-off-by: Alex Tsitsimpis <alextsi@arrikto.com>

* template: Check Jinja2 support for `lstrip_blocks'

Since the `lstrip_blocks' option was added in Jinja2 version 2.7, raise
an exception when `lstrip_blocks' is set but Jinja2 does not support it.
Check support for `lstrip_blocks' option by checking `jinja2.defaults'
for `LSTRIP_BLOCKS' and do not use `jinja2.__version__' because the
latter is set to `unknown' in some cases, perhaps due to bug in
`pkg_resources' in Python 2.6.6.

Also update option description to state that Jinja2 version >=2.7 is
required.

Signed-off-by: Alex Tsitsimpis <alextsi@arrikto.com>
2018-03-23 12:05:21 -04:00
Martin Krizek
63fdc3f08f
Fix jinja2>=2.9 nested include vars ()
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 
2018-02-07 10:58:29 +01:00
Pilou
d608eb9530 Check that AnsibleUndefinedVariable doesn't occur when an unused variable references an undefined variable ()
* Check that AnsibleUndefinedVariable doesn't occur

* AnsibleUndefinedVariable exc.: don't modify type
2018-02-02 09:25:13 -08:00
Matt Martz
4fe08441be Deprecate tests used as filters ()
* 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
2017-11-27 17:58:08 -05:00
Toshio Kuratomi
bc66faa328 Add more tests for copy/file/template with harlinks 2017-08-17 18:16:17 -07:00
Andrew Erickson
2b14fdbce3 add test for template, file, and copy with hardlinks 2017-08-17 18:16:17 -07:00
Adrian Likins
359ced3833 rm unused test template in template intg tests
introduced in 501fc7a248
based on my patch.
2017-08-12 03:28:07 -07:00
Zac Medico
501fc7a248 template: fix KeyError: 'undefined variable: 0 ()
* 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
2017-08-09 18:50:53 -04:00
jctanner
baf1ed9100 [WIP] Create preserved_copy function in basic.py to perserve file ownership. ()
Create preserved_copy function in basic.py to perserve file ownership.

* Add a test for template preserved backup
* Use a script to get the random names
* bytes to strings
* Remove dump of hostvars
* Stop being fancy and create a testuser instead
* Fix pep8
* set file attributes
* Pass the correct data to set_attributes_if_different
* Use -j instead -b and pass the attributes as a string instead of a list
* remove debugging message
* Use shell to softly set the attr

Fixes 
2017-08-02 10:04:09 -04:00
Dag Wieers
ac43a1bbbc Windows: Use the correct newline sequence for the platform ()
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 
2017-03-23 19:47:10 -07:00
Matt Clay
61e6e7868c Improve jinja2 test coverage. ()
* Run `template` test on latest jinja2 version.
* Update jinja2 install for groupby_filter.
* Clean test output dir for each test.
2017-01-20 16:38:52 -08:00
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 

(cherry picked from commit 4d49b317929b86e1fc1b0cbace825ff73b372dc7)
2017-01-20 07:15:51 -06:00
Carlos E. Garcia
0b8011436d minor spelling changes 2016-12-13 13:51:13 -05:00
Matt Clay
6bbd92e422 Initial ansible-test implementation. () 2016-11-29 21:21:53 -08:00
Matt Clay
3fd13aaffe Detect default group in template integration test. 2016-11-23 11:28:28 -08:00
Adrien Vergé
0e834fc9e4 Fix cosmetic problems in YAML source
This change corrects problems reported by the `yamllint` linter.

Since key duplication problems were removed in 4d48711, this commit
mainly fixes trailing spaces and extra empty lines at beginning/end of
files.
2016-11-11 14:50:57 -08:00
Matt Clay
75e4645ee7 Migrate Linux CI roles to test targets. () 2016-10-13 09:09:25 -07:00