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