| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -eux |
| 4 |
|
| 5 |
# test no dupes when dependencies in b and c point to a in roles: |
| 6 |
[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags inroles | grep -c '"msg": "A"')" = "1" ] |
| 7 |
[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags acrossroles | grep -c '"msg": "A"')" = "1" ] |
| 8 |
[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags intasks | grep -c '"msg": "A"')" = "1" ] |
| 9 |
|
| 10 |
# but still dupe across plays |
| 11 |
[ "$(ansible-playbook no_dupes.yml -i ../../inventory | grep -c '"msg": "A"')" = "3" ] |
| 12 |
|
| 13 |
# and don't dedupe before the role successfully completes |
| 14 |
[ "$(ansible-playbook role_complete.yml -i ../../inventory -i fake, --tags conditional_skipped | grep -c '"msg": "A"')" = "1" ] |
| 15 |
[ "$(ansible-playbook role_complete.yml -i ../../inventory -i fake, --tags conditional_failed | grep -c '"msg": "failed_when task succeeded"')" = "1" ] |
| 16 |
[ "$(ANSIBLE_INJECT_INVOCATION=1 ansible-playbook role_complete.yml -i ../../inventory -i fake, --tags unreachable -vvv | grep -c '"data": "reachable"')" = "1" ] |
| 17 |
ansible-playbook role_complete.yml -i ../../inventory -i fake, --tags unreachable | grep -e 'ignored=2' |
| 18 |
|
| 19 |
# include/import can execute another instance of role |
| 20 |
[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags importrole | grep -c '"msg": "A"')" = "2" ] |
| 21 |
[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags includerole | grep -c '"msg": "A"')" = "2" ] |
| 22 |
|
| 23 |
[ "$(ansible-playbook dupe_inheritance.yml -i ../../inventory | grep -c '"msg": "abc"')" = "3" ] |
| 24 |
|
| 25 |
# ensure role data is merged correctly |
| 26 |
ansible-playbook data_integrity.yml -i ../../inventory "$@" |
| 27 |
|
| 28 |
# ensure role fails when trying to load 'non role' in _from |
| 29 |
test_no_outside=("no_outside.yml" "no_outside_import.yml") |
| 30 |
for file in "${test_no_outside[@]}"; do |
| 31 |
ansible-playbook "$file" -i ../../inventory > "${file}_output.log" 2>&1 || true |
| 32 |
if grep "as it is not inside the expected role path" "${file}_output.log" >/dev/null; then |
| 33 |
echo "Test passed for $file (playbook failed with expected output, output not shown)." |
| 34 |
else |
| 35 |
echo "Test failed for $file, expected output from playbook failure is missing, output not shown)." |
| 36 |
exit 1 |
| 37 |
fi |
| 38 |
done |
| 39 |
|
| 40 |
# ensure subdir contained to role in tasks_from is valid |
| 41 |
ansible-playbook test_subdirs.yml -i ../../inventory "$@" |
| 42 |
|
| 43 |
# ensure vars scope is correct |
| 44 |
ansible-playbook vars_scope.yml -i ../../inventory "$@" |
| 45 |
|
| 46 |
# test nested includes get parent roles greater than a depth of 3 |
| 47 |
[ "$(ansible-playbook 47023.yml -i ../../inventory | grep '\<\(Default\|Var\)\>' | grep -c 'is defined')" = "2" ] |
| 48 |
|
| 49 |
# ensure import_role called from include_role has the include_role in the dep chain |
| 50 |
ansible-playbook role_dep_chain.yml -i ../../inventory "$@" |
| 51 |
|
| 52 |
# global role privacy setting test, set to private, set to not private, default |
| 53 |
ANSIBLE_PRIVATE_ROLE_VARS=1 ansible-playbook privacy.yml -e @vars/privacy_vars.yml "$@" |
| 54 |
ANSIBLE_PRIVATE_ROLE_VARS=0 ansible-playbook privacy.yml -e @vars/privacy_vars.yml "$@" |
| 55 |
ansible-playbook privacy.yml -e @vars/privacy_vars.yml "$@" |
| 56 |
|
| 57 |
for strategy in linear free; do |
| 58 |
[ "$(ANSIBLE_STRATEGY=$strategy ansible-playbook -i testhost, end_role.yml | grep -c CHECKPOINT)" = "2" ] |
| 59 |
[ "$(ANSIBLE_STRATEGY=$strategy ansible-playbook -i host1,host2 end_role_nested.yml | grep -c CHECKPOINT)" = "4" ] |
| 60 |
done |
| 61 |
|
| 62 |
[ "$(ansible localhost -m meta -a end_role 2>&1 | grep -c "\[ERROR\]: Cannot execute 'end_role' from outside of a role")" = "1" ] |
| 63 |
[ "$(ansible-playbook end_role_handler_error.yml 2>&1 | grep -c "\[ERROR\]: Cannot execute 'end_role' from a handler")" = "1" ] |
| 64 |
|
| 65 |
# include_role should work in rescue, even if error is from magic variable templating |
| 66 |
ansible-playbook 75240.yml -i ../../inventory "$@" |