mirror of https://github.com/ansible/ansible.git
Add some missing files for filters and ignore_errors tests
parent
fa1ab231c9
commit
b2e5903853
@ -0,0 +1,73 @@
|
|||||||
|
This is a test of various filter plugins found in Ansible (ex: core.py), and
|
||||||
|
not so much a test of the core filters in Jinja2.
|
||||||
|
|
||||||
|
Dumping a nested structure to JSON
|
||||||
|
|
||||||
|
[
|
||||||
|
"this is a list element",
|
||||||
|
{
|
||||||
|
"this": "is a hash element in a list",
|
||||||
|
"warp": 9,
|
||||||
|
"where": "endor"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
Dumping the same structure to YAML
|
||||||
|
|
||||||
|
- this is a list element
|
||||||
|
- this: is a hash element in a list
|
||||||
|
warp: 9
|
||||||
|
where: endor
|
||||||
|
|
||||||
|
|
||||||
|
Dumping the same structure to JSON, but don't pretty print
|
||||||
|
|
||||||
|
["this is a list element", {"this": "is a hash element in a list", "where": "endor", "warp": 9}]
|
||||||
|
|
||||||
|
Dumping the same structure to YAML, but don't pretty print
|
||||||
|
|
||||||
|
- this is a list element
|
||||||
|
- {this: is a hash element in a list, warp: 9, where: endor}
|
||||||
|
|
||||||
|
|
||||||
|
From a recorded task, the changed, failed, success, and skipped
|
||||||
|
filters are shortcuts to ask if those tasks produced changes, failed,
|
||||||
|
succeeded, or skipped (as one might guess).
|
||||||
|
|
||||||
|
Changed = True
|
||||||
|
Failed = False
|
||||||
|
Success = True
|
||||||
|
Skipped = False
|
||||||
|
|
||||||
|
The mandatory filter fails if a variable is not defined and returns the value.
|
||||||
|
To avoid breaking this test, this variable is already defined.
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
|
||||||
|
There are various casts available
|
||||||
|
|
||||||
|
int = 1
|
||||||
|
bool = True
|
||||||
|
|
||||||
|
String quoting
|
||||||
|
|
||||||
|
quoted = quoted
|
||||||
|
|
||||||
|
The fileglob module returns the list of things matching a pattern.
|
||||||
|
|
||||||
|
fileglob = []
|
||||||
|
|
||||||
|
There are also various string operations that work on paths. These do not require
|
||||||
|
files to exist and are passthrus to the python os.path functions
|
||||||
|
|
||||||
|
'~/foo' with expanduser = /root/foo
|
||||||
|
/etc/motd with basename = motd
|
||||||
|
/etc/motd with dirname = /etc
|
||||||
|
|
||||||
|
TODO: realpath follows symlinks. There isn't a test for this just now.
|
||||||
|
|
||||||
|
TODO: add tests for set theory operations like union
|
||||||
|
|
||||||
|
TODO: add tests for regex, match, and search
|
||||||
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- prepare_tests
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
# test code
|
||||||
|
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||||
|
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
- name: a dummy task to test the changed and success filters
|
||||||
|
shell: echo hi
|
||||||
|
register: some_registered_var
|
||||||
|
|
||||||
|
- debug: var=some_registered_var
|
||||||
|
|
||||||
|
- name: fill in a basic template
|
||||||
|
template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644
|
||||||
|
register: template_result
|
||||||
|
|
||||||
|
- name: copy known good into place
|
||||||
|
copy: src=foo.txt dest={{output_dir}}/foo.txt
|
||||||
|
|
||||||
|
- name: compare templated file to known good
|
||||||
|
shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
|
||||||
|
register: diff_result
|
||||||
|
|
||||||
|
- name: verify templated file matches known good
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'diff_result.stdout == ""'
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
This is a test of various filter plugins found in Ansible (ex: core.py), and
|
||||||
|
not so much a test of the core filters in Jinja2.
|
||||||
|
|
||||||
|
Dumping a nested structure to JSON
|
||||||
|
|
||||||
|
{{ some_structure | to_nice_json }}
|
||||||
|
|
||||||
|
Dumping the same structure to YAML
|
||||||
|
|
||||||
|
{{ some_structure | to_nice_yaml }}
|
||||||
|
|
||||||
|
Dumping the same structure to JSON, but don't pretty print
|
||||||
|
|
||||||
|
{{ some_structure | to_json }}
|
||||||
|
|
||||||
|
Dumping the same structure to YAML, but don't pretty print
|
||||||
|
|
||||||
|
{{ some_structure | to_yaml }}
|
||||||
|
|
||||||
|
From a recorded task, the changed, failed, success, and skipped
|
||||||
|
filters are shortcuts to ask if those tasks produced changes, failed,
|
||||||
|
succeeded, or skipped (as one might guess).
|
||||||
|
|
||||||
|
Changed = {{ some_registered_var | changed }}
|
||||||
|
Failed = {{ some_registered_var | failed }}
|
||||||
|
Success = {{ some_registered_var | success }}
|
||||||
|
Skipped = {{ some_registered_var | skipped }}
|
||||||
|
|
||||||
|
The mandatory filter fails if a variable is not defined and returns the value.
|
||||||
|
To avoid breaking this test, this variable is already defined.
|
||||||
|
|
||||||
|
a = {{ a | mandatory }}
|
||||||
|
|
||||||
|
There are various casts available
|
||||||
|
|
||||||
|
int = {{ a | int }}
|
||||||
|
bool = {{ 1 | bool }}
|
||||||
|
|
||||||
|
String quoting
|
||||||
|
|
||||||
|
quoted = {{ 'quoted' | quote }}
|
||||||
|
|
||||||
|
The fileglob module returns the list of things matching a pattern.
|
||||||
|
|
||||||
|
fileglob = {{ (output_dir + '/*') | fileglob }}
|
||||||
|
|
||||||
|
There are also various string operations that work on paths. These do not require
|
||||||
|
files to exist and are passthrus to the python os.path functions
|
||||||
|
|
||||||
|
'~/foo' with expanduser = {{ '~/foo' | expanduser }}
|
||||||
|
/etc/motd with basename = {{ '/etc/motd' | basename }}
|
||||||
|
/etc/motd with dirname = {{ '/etc/motd' | dirname }}
|
||||||
|
|
||||||
|
TODO: realpath follows symlinks. There isn't a test for this just now.
|
||||||
|
|
||||||
|
TODO: add tests for set theory operations like union
|
||||||
|
|
||||||
|
TODO: add tests for regex, match, and search
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
some_structure:
|
||||||
|
- "this is a list element"
|
||||||
|
-
|
||||||
|
this: "is a hash element in a list"
|
||||||
|
warp: 9
|
||||||
|
where: endor
|
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- prepare_tests
|
||||||
|
|
Loading…
Reference in New Issue