|
|
|
@ -61,42 +61,6 @@
|
|
|
|
|
that:
|
|
|
|
|
- 'diff_result.stdout == ""'
|
|
|
|
|
|
|
|
|
|
- name: Verify human_readable
|
|
|
|
|
tags: "human_readable"
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- '"1.00 Bytes" == 1|human_readable'
|
|
|
|
|
- '"1.00 bits" == 1|human_readable(isbits=True)'
|
|
|
|
|
- '"10.00 KB" == 10240|human_readable'
|
|
|
|
|
- '"97.66 MB" == 102400000|human_readable'
|
|
|
|
|
- '"0.10 GB" == 102400000|human_readable(unit="G")'
|
|
|
|
|
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
|
|
|
|
|
|
|
|
|
|
- name: Verify human_to_bytes
|
|
|
|
|
tags: "human_to_bytes"
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "{{'0'|human_to_bytes}} == 0"
|
|
|
|
|
- "{{'0.1'|human_to_bytes}} == 0"
|
|
|
|
|
- "{{'0.9'|human_to_bytes}} == 1"
|
|
|
|
|
- "{{'1'|human_to_bytes}} == 1"
|
|
|
|
|
- "{{'10.00 KB'|human_to_bytes}} == 10240"
|
|
|
|
|
- "{{ '11 MB'|human_to_bytes}} == 11534336"
|
|
|
|
|
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
|
|
|
|
|
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
|
|
|
|
|
|
|
|
|
|
- name: Verify human_to_bytes (bad string)
|
|
|
|
|
set_fact:
|
|
|
|
|
bad_string: "{{ '10.00 foo' | human_to_bytes }}"
|
|
|
|
|
ignore_errors: yes
|
|
|
|
|
tags: human_to_bytes
|
|
|
|
|
register: _human_bytes_test
|
|
|
|
|
|
|
|
|
|
- name: Verify human_to_bytes (bad string)
|
|
|
|
|
tags: human_to_bytes
|
|
|
|
|
assert:
|
|
|
|
|
that: "{{_human_bytes_test.failed}}"
|
|
|
|
|
|
|
|
|
|
- name: Test extract
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
@ -139,62 +103,12 @@
|
|
|
|
|
- "'localhost' | extract(hostvars, ['badsubkey', 'subsubkey']) | default('a') == 'a'"
|
|
|
|
|
- "('localhost' | extract(hostvars, 'badsubkey')).subsubkey | default('a') == 'a'"
|
|
|
|
|
|
|
|
|
|
- name: Test json_query filter
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']"
|
|
|
|
|
|
|
|
|
|
- name: Test hash filter
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- '"{{ "hash" | hash("sha1") }}" == "2346ad27d7568ba9896f1b7da6b5991251debdf2"'
|
|
|
|
|
- '"{{ "café" | hash("sha1") }}" == "f424452a9673918c6f09b0cdd35b20be8e6ae7d7"'
|
|
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
|
var: "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit"
|
|
|
|
|
verbosity: 1
|
|
|
|
|
tags: debug
|
|
|
|
|
|
|
|
|
|
- name: Test urlsplit filter
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('fragment') == 'fragment'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('hostname') == 'www.acme.com'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('netloc') == 'mary:MySecret@www.acme.com:9000'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('path') == '/dir/index.html'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('port') == 9000"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('query') == 'query=term'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('scheme') == 'http'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('username') == 'mary'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('password') == 'MySecret'"
|
|
|
|
|
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit == { 'fragment': 'fragment', 'hostname': 'www.acme.com', 'netloc': 'mary:MySecret@www.acme.com:9000', 'password': 'MySecret', 'path': '/dir/index.html', 'port': 9000, 'query': 'query=term', 'scheme': 'http', 'username': 'mary' }"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Test urlsplit filter bad argument
|
|
|
|
|
debug:
|
|
|
|
|
var: "'http://www.acme.com:9000/dir/index.html' | urlsplit('bad_filter')"
|
|
|
|
|
register: _bad_urlsplit_filter
|
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
|
|
- name: Verify urlsplit filter showed an error message
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- _bad_urlsplit_filter is failed
|
|
|
|
|
- "'unknown URL component' in _bad_urlsplit_filter.msg"
|
|
|
|
|
|
|
|
|
|
- name: Test urldecode filter
|
|
|
|
|
set_fact:
|
|
|
|
|
urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°)
|
|
|
|
|
|
|
|
|
|
- name: Test urlencode filter
|
|
|
|
|
set_fact:
|
|
|
|
|
urlencoded_string: '{{ urldecoded_string|urlencode }}'
|
|
|
|
|
|
|
|
|
|
- name: Verify urlencode en urldecode
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- urldecoded_string == urlencoded_string|urldecode
|
|
|
|
|
|
|
|
|
|
- name: Flatten tests
|
|
|
|
|
block:
|
|
|
|
|
- name: use flatten
|
|
|
|
@ -274,46 +188,6 @@
|
|
|
|
|
- "'00:00:00' | random_mac(seed='test') == '00:00:00' | random_mac(seed='test')"
|
|
|
|
|
- "'00:00:00' | random_mac(seed='test') != '00:00:00' | random_mac(seed='another_test')"
|
|
|
|
|
|
|
|
|
|
- name: Verify that union can be chained
|
|
|
|
|
vars:
|
|
|
|
|
unions: '{{ [1,2,3]|union([4,5])|union([6,7]) }}'
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "unions|type_debug == 'list'"
|
|
|
|
|
- "unions|length == 7"
|
|
|
|
|
|
|
|
|
|
- name: Test union with unhashable item
|
|
|
|
|
vars:
|
|
|
|
|
unions: '{{ [1,2,3]|union([{}]) }}'
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "unions|type_debug == 'list'"
|
|
|
|
|
- "unions|length == 4"
|
|
|
|
|
|
|
|
|
|
- name: Test ipaddr filter
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'"
|
|
|
|
|
- "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'"
|
|
|
|
|
- "not '192.168.0.1/31' | ipaddr('broadcast')"
|
|
|
|
|
- "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'"
|
|
|
|
|
- "'192.168.0.1/24' | ipaddr('prefix') == 24"
|
|
|
|
|
- "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'"
|
|
|
|
|
- "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'"
|
|
|
|
|
- "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'"
|
|
|
|
|
- "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'"
|
|
|
|
|
- "{{ subnets | ipaddr(1) }} == ['10.1.1.1/24', '10.1.2.1/24']"
|
|
|
|
|
- "{{ subnets | ipaddr('1') }} == ['10.1.1.1/24', '10.1.2.1/24']"
|
|
|
|
|
- "{{ subnets | ipaddr(-1) }} == ['10.1.1.255/24', '10.1.2.255/24']"
|
|
|
|
|
- "{{ subnets | ipaddr('-1') }} == ['10.1.1.255/24', '10.1.2.255/24']"
|
|
|
|
|
- "'{{ prefix | ipaddr(1) }}' == '10.1.1.1/24'"
|
|
|
|
|
- "'{{ prefix | ipaddr('1') }}' == '10.1.1.1/24'"
|
|
|
|
|
- "'{{ prefix | ipaddr('network') }}' == '10.1.1.0'"
|
|
|
|
|
- "'{{ prefix | ipaddr('-1') }}' == '10.1.1.255/24'"
|
|
|
|
|
vars:
|
|
|
|
|
subnets: ['10.1.1.0/24', '10.1.2.0/24']
|
|
|
|
|
prefix: '10.1.1.0/24'
|
|
|
|
|
|
|
|
|
|
- name: Ensure dict2items works with hostvars
|
|
|
|
|
debug:
|
|
|
|
|
msg: "{{ item.key }}"
|