[stable-9] Fix/improve tests (#9861)

Fix/improve tests (#9859)

* Fix tests.

* Improve callback tests.

(cherry picked from commit eff25c8a6e)
This commit is contained in:
Felix Fontein 2025-03-09 17:15:21 +01:00 committed by GitHub
parent 0ccb961ff7
commit de754eacbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 184 additions and 154 deletions

View file

@ -0,0 +1,54 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.module_utils.six import string_types
def callback_results_extractor(outputs_results):
results = []
for result in outputs_results:
differences = []
expected_output = result['test']['expected_output']
stdout_lines = result['stdout_lines']
for i in range(max(len(expected_output), len(stdout_lines))):
line = "line_%s" % (i + 1)
test_line = stdout_lines[i] if i < len(stdout_lines) else None
expected_lines = expected_output[i] if i < len(expected_output) else None
if not isinstance(expected_lines, string_types) and expected_lines is not None:
if test_line not in expected_lines:
differences.append({
'line': {
'expected_one_of': expected_lines,
'got': test_line,
}
})
else:
if test_line != expected_lines:
differences.append({
'line': {
'expected': expected_lines,
'got': test_line,
}
})
results.append({
'name': result['test']['name'],
'output': {
'differences': differences,
'expected': expected_output,
'got': stdout_lines,
},
})
return results
class FilterModule:
''' Jinja2 compat filters '''
def filters(self):
return {
'callback_results_extractor': callback_results_extractor,
}

View file

@ -50,44 +50,11 @@
- name: Assert test output equals expected output - name: Assert test output equals expected output
assert: assert:
that: result.output.differences | length == 0 that: result.output.differences | length == 0
loop: "{{ results }}" loop: "{{ outputs.results | callback_results_extractor }}"
loop_control: loop_control:
loop_var: result loop_var: result
label: "{{ result.name }}" label: "{{ result.name }}"
register: assertions register: assertions
vars:
results: >-
{%- set results = [] -%}
{%- for result in outputs.results -%}
{%- set differences = [] -%}
{%- for i in range([result.test.expected_output | count, result.stdout_lines | count] | max) -%}
{%- set line = "line_%s" | format(i+1) -%}
{%- set test_line = result.stdout_lines[i] | default(none) -%}
{%- set expected_lines = result.test.expected_output[i] | default(none) -%}
{%- if expected_lines is not string and expected_lines is not none -%}
{%- if test_line not in expected_lines -%}
{{- differences.append({
line: {
'expected_one_of': expected_lines,
'got': test_line }}) -}}
{%- endif -%}
{%- else -%}
{%- if expected_lines != test_line -%}
{{- differences.append({
line: {
'expected': expected_lines,
'got': test_line }}) -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{{- results.append({
'name': result.test.name,
'output': {
'differences': differences,
'expected': result.test.expected_output,
'got': result.stdout_lines }}) -}}
{%- endfor -%}
{{- results -}}
always: always:
- name: Remove temporary playbooks - name: Remove temporary playbooks

View file

@ -33,7 +33,7 @@
that: that:
- result is changed - result is changed
- result.binding_rule.AuthMethod == 'test' - result.binding_rule.AuthMethod == 'test'
- result.binding.Description == 'test-binding: my description' - "result.binding_rule.Description == 'test-binding: my description'"
- result.operation == 'create' - result.operation == 'create'
- name: Update a binding rule - name: Update a binding rule
@ -46,7 +46,7 @@
- assert: - assert:
that: that:
- result is changed - result is changed
- result.binding.Description == 'test-binding: my description' - "result.binding_rule.Description == 'test-binding: my description'"
- result.operation == 'update' - result.operation == 'update'
- name: Update a binding rule (noop) - name: Update a binding rule (noop)
@ -58,7 +58,7 @@
- assert: - assert:
that: that:
- result is not changed - result is not changed
- result.binding.Description == 'test-binding: my description' - "result.binding_rule.Description == 'test-binding: my description'"
- result.operation is not defined - result.operation is not defined
- name: Delete a binding rule - name: Delete a binding rule

View file

@ -22,7 +22,7 @@
- assert: - assert:
that: that:
- simple_create_result is changed - simple_create_result is changed
- simple_create_result.token.AccessorID - simple_create_result.token.AccessorID is truthy
- simple_create_result.operation == 'create' - simple_create_result.operation == 'create'
- name: Create token - name: Create token
@ -84,5 +84,5 @@
- assert: - assert:
that: that:
- result is changed - result is changed
- not result.token - result.token is falsy
- result.operation == 'remove' - result.operation == 'remove'

View file

@ -123,11 +123,12 @@
register: releases_path register: releases_path
- stat: path={{ deploy_helper.shared_path }} - stat: path={{ deploy_helper.shared_path }}
register: shared_path register: shared_path
when: deploy_helper.shared_path is truthy
- name: Assert State=present with shared_path set to False - name: Assert State=present with shared_path set to False
assert: assert:
that: that:
- "releases_path.stat.exists" - "releases_path.stat.exists"
- "not shared_path.stat.exists" - "deploy_helper.shared_path is falsy or not shared_path.stat.exists"
# Setup older releases for tests # Setup older releases for tests
- file: path={{ deploy_helper.releases_path }}/{{ item }} state=directory - file: path={{ deploy_helper.releases_path }}/{{ item }} state=directory

View file

@ -26,7 +26,7 @@
assert: assert:
that: that:
- res is failed - res is failed
- res.msg is match('Argument for community.general.counter must be a sequence') - res.msg is search('Argument for community.general.counter must be a sequence')
- name: test fail element not hashable - name: test fail element not hashable
debug: debug:
@ -38,4 +38,4 @@
assert: assert:
that: that:
- res is failed - res is failed
- res.msg is match('community.general.counter needs a sequence with hashable elements') - res.msg is search('community.general.counter needs a sequence with hashable elements')

View file

@ -51,4 +51,4 @@
assert: assert:
that: that:
- _invalid_csv_strict_true is failed - _invalid_csv_strict_true is failed
- _invalid_csv_strict_true.msg is match('Unable to process file:.*') - _invalid_csv_strict_true.msg is search('Unable to process file:.*')

View file

@ -16,7 +16,7 @@
- assert: - assert:
that: that:
- result.msg == 'Input is not a sequence' - result.msg is search('Input is not a sequence')
- name: 'Test error: list element not a mapping' - name: 'Test error: list element not a mapping'
set_fact: set_fact:
@ -26,7 +26,7 @@
- assert: - assert:
that: that:
- "result.msg == 'Sequence element #0 is not a mapping'" - "result.msg is search('Sequence element #0 is not a mapping')"
- name: 'Test error: list element does not have attribute' - name: 'Test error: list element does not have attribute'
set_fact: set_fact:
@ -36,7 +36,7 @@
- assert: - assert:
that: that:
- "result.msg == 'Attribute not contained in element #1 of sequence'" - "result.msg is search('Attribute not contained in element #1 of sequence')"
- name: 'Test error: attribute collision' - name: 'Test error: attribute collision'
set_fact: set_fact:
@ -46,4 +46,4 @@
- assert: - assert:
that: that:
- result.msg == "Multiple sequence entries have attribute value 'a'" or result.msg == "Multiple sequence entries have attribute value u'a'" - result.msg is search("Multiple sequence entries have attribute value u?'a'")

View file

@ -31,7 +31,7 @@
- name: Register result of invalid salt - name: Register result of invalid salt
debug: debug:
var: "invalid_input | community.general.hashids_encode(salt=10)" var: "single_int | community.general.hashids_encode(salt=10)"
register: invalid_salt_message register: invalid_salt_message
ignore_errors: true ignore_errors: true
@ -42,7 +42,7 @@
- name: Register result of invalid alphabet - name: Register result of invalid alphabet
debug: debug:
var: "invalid_input | community.general.hashids_encode(alphabet='abc')" var: "single_int | community.general.hashids_encode(alphabet='abc')"
register: invalid_alphabet_message register: invalid_alphabet_message
ignore_errors: true ignore_errors: true
@ -53,7 +53,7 @@
- name: Register result of invalid min_length - name: Register result of invalid min_length
debug: debug:
var: "invalid_input | community.general.hashids_encode(min_length='foo')" var: "single_int | community.general.hashids_encode(min_length='foo')"
register: invalid_min_length_message register: invalid_min_length_message
ignore_errors: true ignore_errors: true

View file

@ -6,7 +6,7 @@
- name: Debug ansible_version - name: Debug ansible_version
ansible.builtin.debug: ansible.builtin.debug:
var: ansible_version var: ansible_version
when: not quite_test | d(true) | bool when: not (quiet_test | default(true) | bool)
tags: ansible_version tags: ansible_version
- name: Tests - name: Tests
@ -19,13 +19,13 @@
fail_msg: | fail_msg: |
[ERR] result: [ERR] result:
{{ result | to_yaml }} {{ result | to_yaml }}
quiet: "{{ quiet_test | d(true) | bool }}" quiet: "{{ quiet_test | default(true) | bool }}"
loop: "{{ tests | subelements('group') }}" loop: "{{ tests | subelements('group') }}"
loop_control: loop_control:
loop_var: i loop_var: i
label: "{{ i.1.mp | d('default') }}: {{ i.1.tt }}" label: "{{ i.1.mp | default('default') }}: {{ i.1.tt }}"
vars: vars:
input: "{{ i.0.input }}" input: "{{ i.0.input }}"
target: "{{ i.1.tt }}" target: "{{ i.1.tt }}"
mp: "{{ i.1.mp | d('default') }}" mp: "{{ i.1.mp | default('default') }}"
result: "{{ lookup('template', i.0.template) }}" result: "{{ lookup('template', i.0.template) }}"

View file

@ -16,7 +16,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result101): my_list|difference(result101):
{{ my_list|difference(result101)|to_nice_yaml|indent(2) }} {{ my_list|difference(result101)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='keep'. assert - name: Merge 2 lists by attribute name. list_merge='keep'. assert
assert: assert:
that: my_list | difference(result101) | length == 0 that: my_list | difference(result101) | length == 0
@ -35,7 +35,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result102): my_list|difference(result102):
{{ my_list|difference(result102)|to_nice_yaml|indent(2) }} {{ my_list|difference(result102)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='append'. assert - name: Merge 2 lists by attribute name. list_merge='append'. assert
assert: assert:
that: my_list | difference(result102) | length == 0 that: my_list | difference(result102) | length == 0
@ -54,7 +54,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result103): my_list|difference(result103):
{{ my_list|difference(result103)|to_nice_yaml|indent(2) }} {{ my_list|difference(result103)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='prepend'. assert - name: Merge 2 lists by attribute name. list_merge='prepend'. assert
assert: assert:
that: my_list | difference(result103) | length == 0 that: my_list | difference(result103) | length == 0
@ -73,7 +73,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result104): my_list|difference(result104):
{{ my_list|difference(result104)|to_nice_yaml|indent(2) }} {{ my_list|difference(result104)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='append_rp'. assert - name: Merge 2 lists by attribute name. list_merge='append_rp'. assert
assert: assert:
that: my_list | difference(result104) | length == 0 that: my_list | difference(result104) | length == 0
@ -92,7 +92,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result105): my_list|difference(result105):
{{ my_list|difference(result105)|to_nice_yaml|indent(2) }} {{ my_list|difference(result105)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='prepend_rp'. assert - name: Merge 2 lists by attribute name. list_merge='prepend_rp'. assert
assert: assert:
that: my_list | difference(result105) | length == 0 that: my_list | difference(result105) | length == 0
@ -115,7 +115,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result200): my_list|difference(result200):
{{ my_list|difference(result200)|to_nice_yaml|indent(2) }} {{ my_list|difference(result200)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge by name. recursive=True list_merge='append_rp'. assert - name: Merge by name. recursive=True list_merge='append_rp'. assert
assert: assert:
that: my_list | difference(result200) | length == 0 that: my_list | difference(result200) | length == 0
@ -136,7 +136,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result201): my_list|difference(result201):
{{ my_list|difference(result201)|to_nice_yaml|indent(2) }} {{ my_list|difference(result201)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge by name. recursive=False list_merge='append_rp'. assert - name: Merge by name. recursive=False list_merge='append_rp'. assert
assert: assert:
that: my_list | difference(result201) | length == 0 that: my_list | difference(result201) | length == 0

View file

@ -6,7 +6,7 @@
- name: Debug ansible_version - name: Debug ansible_version
debug: debug:
var: ansible_version var: ansible_version
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
tags: t0 tags: t0
- name: 1. Test lists merged by attribute name - name: 1. Test lists merged by attribute name
@ -14,7 +14,7 @@
- name: Test lists merged by attribute name debug - name: Test lists merged by attribute name debug
debug: debug:
msg: "{{ list1 | community.general.lists_mergeby(list2, 'name') }}" msg: "{{ list1 | community.general.lists_mergeby(list2, 'name') }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Test lists merged by attribute name assert - name: Test lists merged by attribute name assert
assert: assert:
that: that:
@ -27,7 +27,7 @@
- name: Test list1 empty debug - name: Test list1 empty debug
debug: debug:
msg: "{{ [] | community.general.lists_mergeby(list2, 'name') }}" msg: "{{ [] | community.general.lists_mergeby(list2, 'name') }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Test list1 empty assert - name: Test list1 empty assert
assert: assert:
that: that:
@ -40,7 +40,7 @@
- name: Test all lists empty debug - name: Test all lists empty debug
debug: debug:
msg: "{{ [] | community.general.lists_mergeby([], 'name') }}" msg: "{{ [] | community.general.lists_mergeby([], 'name') }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Test all lists empty assert - name: Test all lists empty assert
assert: assert:
that: that:
@ -58,7 +58,7 @@
- name: First argument must be list debug - name: First argument must be list debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: First argument must be list assert - name: First argument must be list assert
assert: assert:
that: that:
@ -76,7 +76,7 @@
- name: Second argument must be list set debug - name: Second argument must be list set debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Second argument must be list set assert - name: Second argument must be list set assert
assert: assert:
that: that:
@ -94,7 +94,7 @@
- name: First arguments after the lists must be string debug - name: First arguments after the lists must be string debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: First arguments after the lists must be string assert - name: First arguments after the lists must be string assert
assert: assert:
that: that:
@ -112,7 +112,7 @@
- name: Elements of list must be dictionaries debug - name: Elements of list must be dictionaries debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Elements of list must be dictionaries assert - name: Elements of list must be dictionaries assert
assert: assert:
that: that:
@ -128,7 +128,7 @@
- name: Merge 3 lists by attribute name. 1 list in params. debug - name: Merge 3 lists by attribute name. 1 list in params. debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 3 lists by attribute name. 1 list in params. assert - name: Merge 3 lists by attribute name. 1 list in params. assert
assert: assert:
that: my_list | difference(result1) | length == 0 that: my_list | difference(result1) | length == 0
@ -142,7 +142,7 @@
- name: Merge 3 lists by attribute name. No list in the params. debug - name: Merge 3 lists by attribute name. No list in the params. debug
debug: debug:
var: my_list var: my_list
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 3 lists by attribute name. No list in the params. asset - name: Merge 3 lists by attribute name. No list in the params. asset
assert: assert:
that: my_list | difference(result1) | length == 0 that: my_list | difference(result1) | length == 0
@ -162,7 +162,7 @@
{{ my_list|to_nice_yaml|indent(2) }} {{ my_list|to_nice_yaml|indent(2) }}
my_list|difference(result100): my_list|difference(result100):
{{ my_list|difference(result100)|to_nice_yaml|indent(2) }} {{ my_list|difference(result100)|to_nice_yaml|indent(2) }}
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Merge 2 lists by attribute name. list_merge='replace'. assert - name: Merge 2 lists by attribute name. list_merge='replace'. assert
assert: assert:
that: my_list | difference(result100) | length == 0 that: my_list | difference(result100) | length == 0

View file

@ -19,7 +19,7 @@
assert: assert:
that: that:
- _bad_random_mac_filter is failed - _bad_random_mac_filter is failed
- "_bad_random_mac_filter.msg is match('Invalid value type (.*int.*) for random_mac .*')" - "_bad_random_mac_filter.msg is search('Invalid value type (.*int.*) for random_mac .*')"
- name: Test random_mac filter bad argument value - name: Test random_mac filter bad argument value
debug: debug:
@ -31,7 +31,7 @@
assert: assert:
that: that:
- _bad_random_mac_filter is failed - _bad_random_mac_filter is failed
- "_bad_random_mac_filter.msg is match('Invalid value (.*) for random_mac: .* not hexa byte')" - "_bad_random_mac_filter.msg is search('Invalid value (.*) for random_mac: .* not hexa byte')"
- name: Test random_mac filter prefix too big - name: Test random_mac filter prefix too big
debug: debug:
@ -43,7 +43,7 @@
assert: assert:
that: that:
- _bad_random_mac_filter is failed - _bad_random_mac_filter is failed
- "_bad_random_mac_filter.msg is match('Invalid value (.*) for random_mac: 5 colon.* separated items max')" - "_bad_random_mac_filter.msg is search('Invalid value (.*) for random_mac: 5 colon.* separated items max')"
- name: Verify random_mac filter - name: Verify random_mac filter
assert: assert:

View file

@ -6,7 +6,7 @@
- name: Debug ansible_version - name: Debug ansible_version
ansible.builtin.debug: ansible.builtin.debug:
var: ansible_version var: ansible_version
when: not quite_test | d(true) | bool when: not (quiet_test | default(true) | bool)
tags: ansible_version tags: ansible_version
- name: Tests - name: Tests
@ -19,13 +19,13 @@
fail_msg: | fail_msg: |
[ERR] result: [ERR] result:
{{ result | to_yaml }} {{ result | to_yaml }}
quiet: "{{ quiet_test | d(true) | bool }}" quiet: "{{ quiet_test | default(true) | bool }}"
loop: "{{ tests | subelements('group') }}" loop: "{{ tests | subelements('group') }}"
loop_control: loop_control:
loop_var: i loop_var: i
label: "{{ i.1.mp | d('default') }}: {{ i.1.tt }}" label: "{{ i.1.mp | default('default') }}: {{ i.1.tt }}"
vars: vars:
input: "{{ i.0.input }}" input: "{{ i.0.input }}"
target: "{{ i.1.tt }}" target: "{{ i.1.tt }}"
mp: "{{ i.1.mp | d('default') }}" mp: "{{ i.1.mp | default('default') }}"
result: "{{ lookup('template', i.0.template) }}" result: "{{ lookup('template', i.0.template) }}"

View file

@ -6,7 +6,7 @@
- name: Debug ansible_version - name: Debug ansible_version
ansible.builtin.debug: ansible.builtin.debug:
var: ansible_version var: ansible_version
when: not quite_test | d(true) | bool when: not (quiet_test | default(true) | bool)
tags: ansible_version tags: ansible_version
- name: Tests - name: Tests
@ -19,13 +19,13 @@
fail_msg: | fail_msg: |
[ERR] result: [ERR] result:
{{ result | to_yaml }} {{ result | to_yaml }}
quiet: "{{ quiet_test | d(true) | bool }}" quiet: "{{ quiet_test | default(true) | bool }}"
loop: "{{ tests | subelements('group') }}" loop: "{{ tests | subelements('group') }}"
loop_control: loop_control:
loop_var: i loop_var: i
label: "{{ i.1.mp | d('default') }}: {{ i.1.tt }}" label: "{{ i.1.mp | default('default') }}: {{ i.1.tt }}"
vars: vars:
input: "{{ i.0.input }}" input: "{{ i.0.input }}"
target: "{{ i.1.tt }}" target: "{{ i.1.tt }}"
mp: "{{ i.1.mp | d('default') }}" mp: "{{ i.1.mp | default('default') }}"
result: "{{ lookup('template', i.0.template) }}" result: "{{ lookup('template', i.0.template) }}"

View file

@ -10,7 +10,7 @@
that: result == dtype that: result == dtype
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: "abc" data: "abc"
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -21,7 +21,7 @@
that: result == dtype that: result == dtype
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: "abc" data: "abc"
@ -33,7 +33,7 @@
that: result == dtype that: result == dtype
success_msg: '["a", "b", "c"] is {{ dtype }}' success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}' fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: ["a", "b", "c"] data: ["a", "b", "c"]
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -44,7 +44,7 @@
that: result == dtype that: result == dtype
success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}' success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}'
fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}' fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: {"a": "foo", "b": "bar", "c": "baz"} data: {"a": "foo", "b": "bar", "c": "baz"}
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -58,7 +58,7 @@
that: result == dtype that: result == dtype
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ "abc" | community.general.reveal_ansible_type }}' result: '{{ "abc" | community.general.reveal_ansible_type }}'
dtype: str dtype: str
@ -68,7 +68,7 @@
that: result == dtype that: result == dtype
success_msg: '123 is {{ dtype }}' success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}' fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ 123 | community.general.reveal_ansible_type }}' result: '{{ 123 | community.general.reveal_ansible_type }}'
dtype: int dtype: int
@ -78,7 +78,7 @@
that: result == dtype that: result == dtype
success_msg: '123.45 is {{ dtype }}' success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}' fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ 123.45 | community.general.reveal_ansible_type }}' result: '{{ 123.45 | community.general.reveal_ansible_type }}'
dtype: float dtype: float
@ -88,7 +88,7 @@
that: result == dtype that: result == dtype
success_msg: 'true is {{ dtype }}' success_msg: 'true is {{ dtype }}'
fail_msg: 'true is {{ result }}' fail_msg: 'true is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ true | community.general.reveal_ansible_type }}' result: '{{ true | community.general.reveal_ansible_type }}'
dtype: bool dtype: bool
@ -98,7 +98,7 @@
that: result == dtype that: result == dtype
success_msg: '["a", "b", "c"] is {{ dtype }}' success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}' fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}' result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
dtype: list[str] dtype: list[str]
@ -108,7 +108,7 @@
that: result == dtype that: result == dtype
success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}' success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}'
fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}' fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}' result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
dtype: list[dict] dtype: list[dict]
@ -118,7 +118,7 @@
that: result == dtype that: result == dtype
success_msg: '{"a": 1} is {{ dtype }}' success_msg: '{"a": 1} is {{ dtype }}'
fail_msg: '{"a": 1} is {{ result }}' fail_msg: '{"a": 1} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}' result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
dtype: dict[str, int] dtype: dict[str, int]
@ -128,7 +128,7 @@
that: result == dtype that: result == dtype
success_msg: '{"a": 1, "b": 2} is {{ dtype }}' success_msg: '{"a": 1, "b": 2} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 2} is {{ result }}' fail_msg: '{"a": 1, "b": 2} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}' result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
dtype: dict[str, int] dtype: dict[str, int]
@ -141,7 +141,7 @@
that: result == dtype that: result == dtype
success_msg: 'data is {{ dtype }}' success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}' fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 'b': 'b'} data: {1: 'a', 'b': 'b'}
@ -153,7 +153,7 @@
that: result == dtype that: result == dtype
success_msg: 'data is {{ dtype }}' success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}' fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 2: 'b'} data: {1: 'a', 2: 'b'}
@ -165,7 +165,7 @@
that: result == dtype that: result == dtype
success_msg: 'data is {{ dtype }}' success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}' fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}} data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
@ -177,7 +177,7 @@
that: result == dtype that: result == dtype
success_msg: 'data is {{ dtype }}' success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}' fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}] data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]

View file

@ -253,7 +253,7 @@
path: "{{ output_file }}" path: "{{ output_file }}"
section: mysqld section: mysqld
option: "{{ item.o }}" option: "{{ item.o }}"
value: "{{ item.v | d(omit) }}" value: "{{ item.v | default(omit) }}"
allow_no_value: true allow_no_value: true
loop: loop:
- { o: "skip-name-resolve" } - { o: "skip-name-resolve" }
@ -512,10 +512,10 @@
- name: test-value 20 - Tests with empty strings - name: test-value 20 - Tests with empty strings
ini_file: ini_file:
path: "{{ output_file }}" path: "{{ output_file }}"
section: "{{ item.section | d('extensions') }}" section: "{{ item.section | default('extensions') }}"
option: "{{ item.option }}" option: "{{ item.option }}"
value: "" value: ""
allow_no_value: "{{ item.no_value | d(omit) }}" allow_no_value: "{{ item.no_value | default(omit) }}"
loop: loop:
- option: evolve - option: evolve
- option: regress - option: regress

View file

@ -70,7 +70,7 @@
async: "{{ ansible_timeout }}" async: "{{ ansible_timeout }}"
poll: 0 poll: 0
vars: vars:
ansible_timeout: "{{ max_delay | d(300) }}" ansible_timeout: "{{ max_delay | default(300) }}"
rescue: rescue:
- name: "explain expected failure" - name: "explain expected failure"
@ -179,7 +179,7 @@
async: "{{ ansible_timeout }}" async: "{{ ansible_timeout }}"
poll: 0 poll: 0
vars: vars:
ansible_timeout: "{{ max_delay | d(300) }}" ansible_timeout: "{{ max_delay | default(300) }}"
rescue: rescue:
- name: "explain expected failure" - name: "explain expected failure"

View file

@ -26,7 +26,7 @@
- name: Read certificate keys - name: Read certificate keys
slurp: slurp:
src: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.key' }}" src: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.key' }}"
loop: "{{ java_keystore_certs }}" loop: "{{ java_keystore_certs }}"
when: not remote_cert when: not remote_cert
register: certificate_keys register: certificate_keys
@ -34,15 +34,15 @@
- name: Create a Java keystore for the given ({{ 'remote' if remote_cert else 'local' }}) certificates (check mode) - name: Create a Java keystore for the given ({{ 'remote' if remote_cert else 'local' }}) certificates (check mode)
community.general.java_keystore: &java_keystore_params community.general.java_keystore: &java_keystore_params
name: example name: example
dest: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.jks' }}" dest: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.jks' }}"
certificate: "{{ omit if remote_cert else (certificates.results[loop_index].content | b64decode) }}" certificate: "{{ omit if remote_cert else (certificates.results[loop_index].content | b64decode) }}"
private_key: "{{ omit if remote_cert else (certificate_keys.results[loop_index].content | b64decode) }}" private_key: "{{ omit if remote_cert else (certificate_keys.results[loop_index].content | b64decode) }}"
certificate_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ item.name ~ '.pem' }}" certificate_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ item.name ~ '.pem' }}"
private_key_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.key' }}" private_key_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.key' }}"
private_key_passphrase: "{{ item.passphrase | d(omit) }}" private_key_passphrase: "{{ item.passphrase | default(omit) }}"
password: changeit password: changeit
ssl_backend: "{{ ssl_backend }}" ssl_backend: "{{ ssl_backend }}"
keystore_type: "{{ item.keystore_type | d(omit) }}" keystore_type: "{{ item.keystore_type | default(omit) }}"
loop: "{{ java_keystore_certs }}" loop: "{{ java_keystore_certs }}"
loop_control: loop_control:
index_var: loop_index index_var: loop_index
@ -82,7 +82,7 @@
- name: Read certificate keys (new) - name: Read certificate keys (new)
slurp: slurp:
src: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.key' }}" src: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.key' }}"
loop: "{{ java_keystore_new_certs }}" loop: "{{ java_keystore_new_certs }}"
when: not remote_cert when: not remote_cert
register: certificate_keys_new register: certificate_keys_new
@ -90,15 +90,15 @@
- name: Create a Java keystore for the given certificates (certificate changed, check mode) - name: Create a Java keystore for the given certificates (certificate changed, check mode)
community.general.java_keystore: &java_keystore_params_new_certs community.general.java_keystore: &java_keystore_params_new_certs
name: example name: example
dest: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.jks' }}" dest: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.jks' }}"
certificate: "{{ omit if remote_cert else (certificates_new.results[loop_index].content | b64decode) }}" certificate: "{{ omit if remote_cert else (certificates_new.results[loop_index].content | b64decode) }}"
private_key: "{{ omit if remote_cert else (certificate_keys_new.results[loop_index].content | b64decode) }}" private_key: "{{ omit if remote_cert else (certificate_keys_new.results[loop_index].content | b64decode) }}"
certificate_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ item.name ~ '.pem' }}" certificate_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ item.name ~ '.pem' }}"
private_key_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.key' }}" private_key_path: "{{ omit if not remote_cert else remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.key' }}"
private_key_passphrase: "{{ item.passphrase | d(omit) }}" private_key_passphrase: "{{ item.passphrase | default(omit) }}"
password: changeit password: changeit
ssl_backend: "{{ ssl_backend }}" ssl_backend: "{{ ssl_backend }}"
keystore_type: "{{ item.keystore_type | d(omit) }}" keystore_type: "{{ item.keystore_type | default(omit) }}"
loop: "{{ java_keystore_new_certs }}" loop: "{{ java_keystore_new_certs }}"
loop_control: loop_control:
index_var: loop_index index_var: loop_index
@ -193,7 +193,7 @@
- name: Stat keystore (before failure) - name: Stat keystore (before failure)
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.jks' }}" path: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.jks' }}"
loop: "{{ java_keystore_new_certs }}" loop: "{{ java_keystore_new_certs }}"
register: result_stat_before register: result_stat_before
@ -211,7 +211,7 @@
- name: Stat keystore (after failure) - name: Stat keystore (after failure)
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | d(item.name)) ~ '.jks' }}" path: "{{ remote_tmp_dir ~ '/' ~ (item.keyname | default(item.name)) ~ '.jks' }}"
loop: "{{ java_keystore_new_certs }}" loop: "{{ java_keystore_new_certs }}"
register: result_stat_after register: result_stat_after

View file

@ -51,7 +51,7 @@
- orig_stat.stat.size == stat_test_1.stat.size - orig_stat.stat.size == stat_test_1.stat.size
- orig_stat.stat.checksum == stat_test_1.stat.checksum - orig_stat.stat.checksum == stat_test_1.stat.checksum
- orig_stat.stat.mtime == stat_test_1.stat.mtime - orig_stat.stat.mtime == stat_test_1.stat.mtime
- stat_test_1.stat.checksum == expected_content | checksum - stat_test_1.stat.checksum == (expected_content | trim + '\n') | checksum
vars: vars:
expected_content: | expected_content: |
# Copyright (c) Ansible Project # Copyright (c) Ansible Project
@ -83,7 +83,7 @@
assert: assert:
that: that:
- bl_test_2 is changed - bl_test_2 is changed
- slurp_test_2.content|b64decode == content - slurp_test_2.content|b64decode == (content | trim + '\n')
vars: vars:
content: | content: |
# Copyright (c) Ansible Project # Copyright (c) Ansible Project
@ -111,7 +111,7 @@
assert: assert:
that: that:
- bl_test_3 is changed - bl_test_3 is changed
- slurp_test_3.content|b64decode == content - slurp_test_3.content|b64decode == (content | trim + '\n')
vars: vars:
content: | content: |
# Copyright (c) Ansible Project # Copyright (c) Ansible Project

View file

@ -151,7 +151,8 @@
- result.end_state.config.enabled == ["true"] - result.end_state.config.enabled == ["true"]
- result.end_state.config.algorithm == ["RS256"] - result.end_state.config.algorithm == ["RS256"]
- result.end_state.config.priority == ["140"] - result.end_state.config.priority == ["140"]
- result.msg == "Realm key testkey would be changed: config.priority ['150'] -> ['140']" - >-
result.msg == "Realm key testkey would be changed: config.priority ['150'] -> ['140']"
- name: Update custom realm key - name: Update custom realm key
community.general.keycloak_realm_key: community.general.keycloak_realm_key:
@ -184,7 +185,8 @@
- result.end_state.config.enabled == ["true"] - result.end_state.config.enabled == ["true"]
- result.end_state.config.algorithm == ["RS256"] - result.end_state.config.algorithm == ["RS256"]
- result.end_state.config.priority == ["140"] - result.end_state.config.priority == ["140"]
- result.msg == "Realm key testkey changed: config.priority ['150'] -> ['140']" - >-
result.msg == "Realm key testkey changed: config.priority ['150'] -> ['140']"
- name: Update custom realm key (test for idempotency) - name: Update custom realm key (test for idempotency)
community.general.keycloak_realm_key: community.general.keycloak_realm_key:

View file

@ -136,7 +136,8 @@
assert: assert:
that: that:
- eval_error is failed - eval_error is failed
- eval_error.msg.startswith("Caught \"'foo' is undefined") - >-
"Caught \"'foo' is undefined" in eval_error.msg
- name: "Test 5: same variable name reused" - name: "Test 5: same variable name reused"
debug: debug:
@ -151,7 +152,8 @@
assert: assert:
that: that:
- eval_error is failed - eval_error is failed
- eval_error.msg.startswith("Caught \"'x' is undefined") - >-
"Caught \"'x' is undefined" in eval_error.msg
- name: "Test 6: multi-value dict" - name: "Test 6: multi-value dict"
debug: debug:
@ -166,7 +168,8 @@
assert: assert:
that: that:
- eval_error is failed - eval_error is failed
- eval_error.msg == 'Parameter 0 must be a one-element dictionary, got 2 elements' - >-
'Parameter 0 must be a one-element dictionary, got 2 elements' in eval_error.msg
- name: "Test 7: empty dict" - name: "Test 7: empty dict"
debug: debug:
@ -180,4 +183,5 @@
assert: assert:
that: that:
- eval_error is failed - eval_error is failed
- eval_error.msg == 'Parameter 0 must be a one-element dictionary, got 0 elements' - >-
'Parameter 0 must be a one-element dictionary, got 0 elements' in eval_error.msg

View file

@ -469,8 +469,10 @@
- '(pkgng_example8_invalid_annotation_failure.results | selectattr("changed") | list | count) == 0' - '(pkgng_example8_invalid_annotation_failure.results | selectattr("changed") | list | count) == 0'
# Invalid strings should always fail # Invalid strings should always fail
- '(pkgng_example8_invalid_annotation_failure.results | rejectattr("failed") | list | count) == 0' - '(pkgng_example8_invalid_annotation_failure.results | rejectattr("failed") | list | count) == 0'
# Invalid strings should not cause an exception # Invalid strings should not cause a module crash
- '(pkgng_example8_invalid_annotation_failure.results | selectattr("exception", "defined") | list | count) == 0' - '(pkgng_example8_invalid_annotation_failure.results | selectattr("module_stdout", "defined") | list | count) == 0'
# Invalid strings should have a proper msg field
- '(pkgng_example8_invalid_annotation_failure.results | selectattr("msg", "match", "failed to annotate zsh, invalid annotate string: .*") | list | count) == 4'
# Verify annotations are unaffected # Verify annotations are unaffected
- '(pkgng_example8_invalid_annotation_verify.stdout_lines | select("search", "(naked_string|invalid_operation|empty_first_tag|validsecond|notag)") | list | count) == 0' - '(pkgng_example8_invalid_annotation_verify.stdout_lines | select("search", "(naked_string|invalid_operation|empty_first_tag|validsecond|notag)") | list | count) == 0'

View file

@ -25,10 +25,10 @@
- name: install cron package - name: install cron package
package: package:
name: '{{ cron_pkg }}' name: '{{ cron_pkg }}'
when: cron_pkg | default(false, true) when: (cron_pkg | default(false, true)) is truthy
register: cron_package_installed register: cron_package_installed
until: cron_package_installed is success until: cron_package_installed is success
- when: faketime_pkg | default(false, true) - when: (faketime_pkg | default(false, true)) is truthy
block: block:
- name: install cron and faketime packages - name: install cron and faketime packages
package: package:

View file

@ -10,7 +10,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: "abc" data: "abc"
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -21,7 +21,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: "abc" data: "abc"
@ -33,7 +33,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '["a", "b", "c"] is {{ dtype }}' success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}' fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: ["a", "b", "c"] data: ["a", "b", "c"]
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -44,7 +44,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}' success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}'
fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}' fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: {"a": "foo", "b": "bar", "c": "baz"} data: {"a": "foo", "b": "bar", "c": "baz"}
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -58,7 +58,7 @@
that: '"abc" is community.general.ansible_type(dtype)' that: '"abc" is community.general.ansible_type(dtype)'
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ "abc" | community.general.reveal_ansible_type }}' result: '{{ "abc" | community.general.reveal_ansible_type }}'
dtype: str dtype: str
@ -68,7 +68,7 @@
that: '123 is community.general.ansible_type(dtype)' that: '123 is community.general.ansible_type(dtype)'
success_msg: '123 is {{ dtype }}' success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}' fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ 123 | community.general.reveal_ansible_type }}' result: '{{ 123 | community.general.reveal_ansible_type }}'
dtype: int dtype: int
@ -78,7 +78,7 @@
that: '123.45 is community.general.ansible_type(dtype)' that: '123.45 is community.general.ansible_type(dtype)'
success_msg: '123.45 is {{ dtype }}' success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}' fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ 123.45 | community.general.reveal_ansible_type }}' result: '{{ 123.45 | community.general.reveal_ansible_type }}'
dtype: float dtype: float
@ -88,7 +88,7 @@
that: 'true is community.general.ansible_type(dtype)' that: 'true is community.general.ansible_type(dtype)'
success_msg: 'true is {{ dtype }}' success_msg: 'true is {{ dtype }}'
fail_msg: 'true is {{ result }}' fail_msg: 'true is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ true | community.general.reveal_ansible_type }}' result: '{{ true | community.general.reveal_ansible_type }}'
dtype: bool dtype: bool
@ -98,7 +98,7 @@
that: '["a", "b", "c"] is community.general.ansible_type(dtype)' that: '["a", "b", "c"] is community.general.ansible_type(dtype)'
success_msg: '["a", "b", "c"] is {{ dtype }}' success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}' fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}' result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
dtype: list[str] dtype: list[str]
@ -108,7 +108,7 @@
that: '[{"a": 1}, {"b": 2}] is community.general.ansible_type(dtype)' that: '[{"a": 1}, {"b": 2}] is community.general.ansible_type(dtype)'
success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}' success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}'
fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}' fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}' result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
dtype: list[dict] dtype: list[dict]
@ -118,7 +118,7 @@
that: '{"a": 1} is community.general.ansible_type(dtype)' that: '{"a": 1} is community.general.ansible_type(dtype)'
success_msg: '{"a": 1} is {{ dtype }}' success_msg: '{"a": 1} is {{ dtype }}'
fail_msg: '{"a": 1} is {{ result }}' fail_msg: '{"a": 1} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}' result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
dtype: dict[str, int] dtype: dict[str, int]
@ -128,7 +128,7 @@
that: '{"a": 1, "b": 2} is community.general.ansible_type(dtype)' that: '{"a": 1, "b": 2} is community.general.ansible_type(dtype)'
success_msg: '{"a": 1, "b": 2} is {{ dtype }}' success_msg: '{"a": 1, "b": 2} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 2} is {{ result }}' fail_msg: '{"a": 1, "b": 2} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}' result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
dtype: dict[str, int] dtype: dict[str, int]
@ -141,7 +141,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"1": "a", "b": "b"} is {{ dtype }}' success_msg: '{"1": "a", "b": "b"} is {{ dtype }}'
fail_msg: '{"1": "a", "b": "b"} is {{ result }}' fail_msg: '{"1": "a", "b": "b"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 'b': 'b'} data: {1: 'a', 'b': 'b'}
@ -153,7 +153,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"1": "a", "2": "b"} is {{ dtype }}' success_msg: '{"1": "a", "2": "b"} is {{ dtype }}'
fail_msg: '{"1": "a", "2": "b"} is {{ result }}' fail_msg: '{"1": "a", "2": "b"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 2: 'b'} data: {1: 'a', 2: 'b'}
@ -165,7 +165,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ dtype }}' success_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ result }}' fail_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}} data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
@ -177,7 +177,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ dtype }}' success_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ dtype }}'
fail_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ result }}' fail_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"AnsibleUnicode": "str"} alias: {"AnsibleUnicode": "str"}
data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}] data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
@ -192,7 +192,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '"abc" is {{ dtype }}' success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}' fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: abc data: abc
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -203,7 +203,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '123 is {{ dtype }}' success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}' fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: 123 data: 123
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -214,7 +214,7 @@
that: data is community.general.ansible_type(dtype) that: data is community.general.ansible_type(dtype)
success_msg: '123.45 is {{ dtype }}' success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}' fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
data: 123.45 data: 123.45
result: '{{ data | community.general.reveal_ansible_type }}' result: '{{ data | community.general.reveal_ansible_type }}'
@ -228,7 +228,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '123 is {{ dtype }}' success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}' fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"int": "number", "float": "number"} alias: {"int": "number", "float": "number"}
data: 123 data: 123
@ -240,7 +240,7 @@
that: data is community.general.ansible_type(dtype, alias) that: data is community.general.ansible_type(dtype, alias)
success_msg: '123.45 is {{ dtype }}' success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}' fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}' quiet: '{{ quiet_test | default(true) | bool }}'
vars: vars:
alias: {"int": "number", "float": "number"} alias: {"int": "number", "float": "number"}
data: 123.45 data: 123.45

View file

@ -6,7 +6,7 @@
- name: Debug ansible_version - name: Debug ansible_version
ansible.builtin.debug: ansible.builtin.debug:
var: ansible_version var: ansible_version
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
tags: t0 tags: t0
- name: 1. Test valid hostnames. Default options. - name: 1. Test valid hostnames. Default options.
@ -14,7 +14,7 @@
- name: "1. Default min_labels=1, allow_underscores=False" - name: "1. Default min_labels=1, allow_underscores=False"
ansible.builtin.debug: ansible.builtin.debug:
msg: "hosts_invalid: {{ hosts_invalid }}" msg: "hosts_invalid: {{ hosts_invalid }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Assert - name: Assert
ansible.builtin.assert: ansible.builtin.assert:
that: hosts_invalid|difference(result)|length == 0 that: hosts_invalid|difference(result)|length == 0
@ -29,7 +29,7 @@
- name: "2. allow_underscores=True, default min_labels=1" - name: "2. allow_underscores=True, default min_labels=1"
ansible.builtin.debug: ansible.builtin.debug:
msg: "hosts_invalid: {{ hosts_invalid }}" msg: "hosts_invalid: {{ hosts_invalid }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Assert - name: Assert
ansible.builtin.assert: ansible.builtin.assert:
that: hosts_invalid|difference(result)|length == 0 that: hosts_invalid|difference(result)|length == 0
@ -45,7 +45,7 @@
- name: "3. allow_underscores=True, min_labels=2" - name: "3. allow_underscores=True, min_labels=2"
ansible.builtin.debug: ansible.builtin.debug:
msg: "hosts_invalid: {{ hosts_invalid }}" msg: "hosts_invalid: {{ hosts_invalid }}"
when: debug_test|d(false)|bool when: debug_test|default(false)|bool
- name: Assert - name: Assert
ansible.builtin.assert: ansible.builtin.assert:
that: hosts_invalid|difference(result)|length == 0 that: hosts_invalid|difference(result)|length == 0