| 1 |
- hosts: testhost |
| 2 |
gather_facts: no |
| 3 |
tasks: |
| 4 |
- name: Use a specially crafted module to see if things were imported correctly |
| 5 |
test: |
| 6 |
register: result |
| 7 |
|
| 8 |
- name: Check that the module imported the correct version of each module_util |
| 9 |
assert: |
| 10 |
that: |
| 11 |
- 'result["abcdefgh"] == "abcdefgh"' |
| 12 |
- 'result["bar0"] == "bar0"' |
| 13 |
- 'result["bar1"] == "bar1"' |
| 14 |
- 'result["bar2"] == "bar2"' |
| 15 |
- 'result["baz1"] == "baz1"' |
| 16 |
- 'result["baz2"] == "baz2"' |
| 17 |
- 'result["foo0"] == "foo0"' |
| 18 |
- 'result["foo1"] == "foo1"' |
| 19 |
- 'result["foo2"] == "foo2"' |
| 20 |
- 'result["qux1"] == "qux1"' |
| 21 |
- 'result["qux2"] == ["qux2:quux", "qux2:quuz"]' |
| 22 |
- 'result["spam1"] == "spam1"' |
| 23 |
- 'result["spam2"] == "spam2"' |
| 24 |
- 'result["spam3"] == "spam3"' |
| 25 |
- 'result["spam4"] == "spam4"' |
| 26 |
- 'result["spam5"] == ["spam5:bacon", "spam5:eggs"]' |
| 27 |
- 'result["spam6"] == ["spam6:bacon", "spam6:eggs"]' |
| 28 |
- 'result["spam7"] == ["spam7:bacon", "spam7:eggs"]' |
| 29 |
- 'result["spam8"] == ["spam8:bacon", "spam8:eggs"]' |
| 30 |
|
| 31 |
# Test that overriding something in module_utils with something in the local library works |
| 32 |
- name: Test that local module_utils overrides facts.py |
| 33 |
test_override: |
| 34 |
register: result |
| 35 |
|
| 36 |
- name: Make sure the we used the local ansible_release.py, not the one shipped with ansible |
| 37 |
assert: |
| 38 |
that: |
| 39 |
- result["data"] == "overridden ansible_release.py" |
| 40 |
|
| 41 |
- name: Test that importing a module that only exists inside of a submodule does not work |
| 42 |
test_failure: |
| 43 |
ignore_errors: True |
| 44 |
register: result |
| 45 |
|
| 46 |
- name: Make sure we failed in AnsiBallZ |
| 47 |
assert: |
| 48 |
that: |
| 49 |
- result is failed |
| 50 |
- result.msg is contains "Could not find imported module support code for ansible.legacy.test_failure. Looked for (['ansible.module_utils.zebra.foo4', 'ansible.module_utils.zebra'])" |
| 51 |
|
| 52 |
- name: Test that alias deprecation works |
| 53 |
test_alias_deprecation: |
| 54 |
baz: 'bar' |
| 55 |
register: result |
| 56 |
|
| 57 |
- name: Assert that the deprecation message is given correctly |
| 58 |
assert: |
| 59 |
that: |
| 60 |
- result.deprecations[-1].msg == "Alias 'baz' is deprecated. See the module docs for more information" |
| 61 |
- result.deprecations[-1].version == '9.99' |
| 62 |
|
| 63 |
- block: |
| 64 |
- import_role: |
| 65 |
name: setup_remote_tmp_dir |
| 66 |
|
| 67 |
- name: Get a string with a \0 in it |
| 68 |
command: echo -e 'hi\0foo' |
| 69 |
register: string_with_null |
| 70 |
|
| 71 |
- name: Use the null string as a module parameter |
| 72 |
lineinfile: |
| 73 |
path: "{{ remote_tmp_dir }}/nulltest" |
| 74 |
line: "{{ string_with_null.stdout }}" |
| 75 |
create: yes |
| 76 |
ignore_errors: yes |
| 77 |
register: nulltest |
| 78 |
|
| 79 |
- name: See if the file exists |
| 80 |
stat: |
| 81 |
path: "{{ remote_tmp_dir }}/nulltest" |
| 82 |
register: nullstat |
| 83 |
|
| 84 |
- assert: |
| 85 |
that: |
| 86 |
- nulltest is failed |
| 87 |
- nulltest.msg_to_log.startswith('Invoked ') |
| 88 |
- nulltest.msg.startswith('Failed to log to syslog') |
| 89 |
# Conditionalize this, because when we log with something other than |
| 90 |
# syslog, it's probably successful and these assertions will fail. |
| 91 |
when: nulltest is failed |
| 92 |
|
| 93 |
# Ensure we fail out early and don't actually run the module if logging |
| 94 |
# failed. |
| 95 |
- assert: |
| 96 |
that: |
| 97 |
- nullstat.stat.exists == nulltest is successful |
| 98 |
always: |
| 99 |
- file: |
| 100 |
path: "{{ remote_tmp_dir }}/nulltest" |
| 101 |
state: absent |
| 102 |
|
| 103 |
- name: Test that date and datetime in module output works |
| 104 |
test_datetime: |
| 105 |
date: "2020-10-05" |
| 106 |
datetime: "2020-10-05T10:05:05" |
| 107 |
register: datetimetest |
| 108 |
|
| 109 |
- assert: |
| 110 |
that: |
| 111 |
- datetimetest.date == '2020-10-05' |
| 112 |
- datetimetest.datetime == '2020-10-05T10:05:05' |
| 113 |
|
| 114 |
- name: Test that optional imports behave properly |
| 115 |
test_optional: |
| 116 |
register: optionaltest |
| 117 |
|
| 118 |
- assert: |
| 119 |
that: |
| 120 |
- optionaltest is success |
| 121 |
- optionaltest.msg == 'all missing optional imports behaved as expected' |