| 1 |
- name: Restrict tests to 'script' |
| 2 |
environment: |
| 3 |
INVENTORY_TEST_MODE: '{{ item.mode | default(omit) }}' |
| 4 |
block: |
| 5 |
- name: run valid script output test cases |
| 6 |
include_tasks: test_valid_inventory.yml |
| 7 |
loop: |
| 8 |
- mode: no_profile |
| 9 |
show_stderr: '1' |
| 10 |
emit_stderr: '1' |
| 11 |
assertions: &standard_assertions |
| 12 |
- inventory_data | length == 5 |
| 13 |
|
| 14 |
- inventory_data._meta | length == 2 |
| 15 |
- inventory_data._meta.hostvars.host1.a_host1_hostvar == "avalue" |
| 16 |
- inventory_data._meta.hostvars.host1.a_host1_hostvar is ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 17 |
- inventory_data._meta.hostvars.localhost.a_localhost_hostvar == "avalue" |
| 18 |
- inventory_data._meta.hostvars.localhost.a_localhost_hostvar is ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 19 |
|
| 20 |
- inventory_data.all | length == 1 |
| 21 |
- inventory_data.all.children | symmetric_difference(["ungrouped", "group1", "empty_group", "list_as_group", "rewrite_as_host"]) | length == 0 |
| 22 |
|
| 23 |
- inventory_data.group1 | length == 2 |
| 24 |
- inventory_data.group1.hosts == ["host1"] |
| 25 |
|
| 26 |
- inventory_data.group1.vars | length == 2 |
| 27 |
- inventory_data.group1.vars.a_group1_groupvar == "avalue" |
| 28 |
- inventory_data.group1.vars.a_group1_groupvar is ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 29 |
- inventory_data.group1.vars.group1_untrusted_var == "untrusted value" |
| 30 |
- inventory_data.group1.vars.group1_untrusted_var is not ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 31 |
|
| 32 |
- inventory_data.rewrite_as_host | length == 2 |
| 33 |
- inventory_data.rewrite_as_host.hosts == ["rewrite_as_host"] |
| 34 |
- inventory_data.rewrite_as_host.vars.avar == "value" |
| 35 |
- inventory_data.rewrite_as_host.vars.avar is not ansible._protomatter.tagged_with "TrustedAsTemplate" # rewritten groups are too hard to trust and are deprecated |
| 36 |
- inv_out.stderr is contains "Treating malformed group 'rewrite_as_host'" |
| 37 |
- inventory_data.rewrite_as_host.vars.untrusted_var == "untrusted value" |
| 38 |
- inventory_data.rewrite_as_host.vars.untrusted_var is not ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 39 |
|
| 40 |
- inventory_data.ungrouped | length == 1 |
| 41 |
- inventory_data.ungrouped.hosts == ["localhost"] |
| 42 |
|
| 43 |
- mode: with_profile |
| 44 |
show_stderr: '1' |
| 45 |
assertions: *standard_assertions |
| 46 |
|
| 47 |
- mode: no_hosts |
| 48 |
assertions: |
| 49 |
- inventory_data | length == 2 |
| 50 |
- inventory_data._meta.hostvars == {} |
| 51 |
|
| 52 |
- inventory_data.all | length == 1 |
| 53 |
- inventory_data.all.children == ["ungrouped"] |
| 54 |
|
| 55 |
- mode: no_meta_hostvars |
| 56 |
assertions: |
| 57 |
- inventory_data | length == 3 |
| 58 |
- inventory_data._meta.hostvars | length == 1 |
| 59 |
- inventory_data._meta.hostvars.myhost.avar == "avalue" |
| 60 |
- inventory_data._meta.hostvars.myhost.avar is ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 61 |
- inventory_data._meta.hostvars.myhost.untrusted == "untrusted value" |
| 62 |
- inventory_data._meta.hostvars.myhost.untrusted is not ansible._protomatter.tagged_with "TrustedAsTemplate" |
| 63 |
|
| 64 |
- inventory_data.all | length == 1 |
| 65 |
- inventory_data.all.children | symmetric_difference(["ungrouped", "mygroup"]) | length == 0 |
| 66 |
|
| 67 |
- inventory_data.mygroup | length == 1 |
| 68 |
- inventory_data.mygroup.hosts == ["myhost"] |
| 69 |
|
| 70 |
- mode: no_meta_hostvars_empty_host_result |
| 71 |
assertions: |
| 72 |
- inventory_data | length == 3 |
| 73 |
- inventory_data._meta.hostvars == {} |
| 74 |
|
| 75 |
- inventory_data.all | length == 1 |
| 76 |
- inventory_data.all.children | symmetric_difference(["ungrouped", "mygroup"]) | length == 0 |
| 77 |
|
| 78 |
- inventory_data.mygroup | length == 1 |
| 79 |
- inventory_data.mygroup.hosts == ["myhost"] |
| 80 |
|
| 81 |
- name: run invalid script output test cases |
| 82 |
include_tasks: test_broken_inventory.yml |
| 83 |
loop: |
| 84 |
- {mode: bad_shebang, script_name: bad_shebang, expected_error: Failed to execute inventory script command} |
| 85 |
- {mode: non_zero_exit, expected_error: Inventory script returned non-zero exit code 1} |
| 86 |
- {mode: invalid_utf8, expected_error: Inventory script result contained characters that cannot be interpreted as UTF-8} |
| 87 |
- {mode: invalid_json, expected_error: Unable to get JSON decoder for inventory script result. Value could not be parsed as JSON} |
| 88 |
- {mode: invalid_type, expected_error: Unable to get JSON decoder for inventory script result. Value is 'str' instead of 'dict'} |
| 89 |
- {mode: invalid_meta_type, expected_error: Unable to get JSON decoder for inventory script result. Value contains '_meta' which is 'str' instead of 'dict'} |
| 90 |
- {mode: invalid_profile_type, expected_error: Unable to get JSON decoder for inventory script result. Value contains '_meta.profile' which is 'int' instead of 'str'} |
| 91 |
- {mode: invalid_profile_name, expected_error: Non-inventory profile 'invalid_profile' is not allowed.} |
| 92 |
- {mode: invalid_inventory_profile_name, expected_error: Unable to get JSON decoder for inventory script result. Unknown profile name 'inventory_invalid_profile'} |
| 93 |
- {mode: invalid_json_for_profile, expected_error: Inventory script result could not be parsed as JSON} |
| 94 |
- {mode: invalid_meta_hostvars_type, expected_error: Value contains '_meta.hostvars' which is 'list' instead of 'dict'} |
| 95 |
- {mode: invalid_meta_hostvars_type_for_host, expected_error: Invalid data from file, expected dictionary and got} |
| 96 |
- {mode: invalid_group_type, expected_error: Value contains 'mygroup.hosts' which is 'NoneType' instead of 'list'} |
| 97 |
- {mode: invalid_group_vars_type, expected_error: Value contains 'mygroup.vars' which is 'list' instead of 'dict'} |
| 98 |
- {mode: no_meta_hostvars_host_nonzero_rc, expected_error: Inventory script returned non-zero exit code 1} |
| 99 |
- {mode: no_meta_hostvars_host_invalid_json, expected_error: Inventory script result for host 'myhost' could not be parsed as JSON} |
| 100 |
- mode: bad_types |
| 101 |
script_name: bad_types |
| 102 |
deprecation: "Group 'bad_group' was converted to 'dict' from 'str'" # this deprecation is removed in 2.23 |
| 103 |
expected_error: "Value contains 'bad_group.hosts' which is 'str' instead of 'list'" |