diff options
Diffstat (limited to 'test/integration/targets/roles')
15 files changed, 104 insertions, 0 deletions
diff --git a/test/integration/targets/roles/aliases b/test/integration/targets/roles/aliases new file mode 100644 index 0000000..1d28bdb --- /dev/null +++ b/test/integration/targets/roles/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +context/controller diff --git a/test/integration/targets/roles/allowed_dupes.yml b/test/integration/targets/roles/allowed_dupes.yml new file mode 100644 index 0000000..998950b --- /dev/null +++ b/test/integration/targets/roles/allowed_dupes.yml @@ -0,0 +1,18 @@ +- name: test that import_role adds one (just one) execution of the role + hosts: localhost + gather_facts: false + tags: ['importrole'] + roles: + - name: a + tasks: + - name: import role ignores dupe rule + import_role: name=a + +- name: test that include_role adds one (just one) execution of the role + hosts: localhost + gather_facts: false + tags: ['includerole'] + roles: + - name: a + tasks: + - include_role: name=a diff --git a/test/integration/targets/roles/data_integrity.yml b/test/integration/targets/roles/data_integrity.yml new file mode 100644 index 0000000..5eb4fb3 --- /dev/null +++ b/test/integration/targets/roles/data_integrity.yml @@ -0,0 +1,4 @@ +- hosts: all + gather_facts: false + roles: + - data diff --git a/test/integration/targets/roles/no_dupes.yml b/test/integration/targets/roles/no_dupes.yml new file mode 100644 index 0000000..7e1ecb1 --- /dev/null +++ b/test/integration/targets/roles/no_dupes.yml @@ -0,0 +1,29 @@ +- name: play should only show 1 invocation of a, as dependencies in this play are deduped + hosts: testhost + gather_facts: false + tags: [ 'inroles' ] + roles: + - role: a + - role: b + - role: c + +- name: play should only show 1 invocation of a, as dependencies in this play are deduped even outside of roles + hosts: testhost + gather_facts: false + tags: [ 'acrossroles' ] + roles: + - role: a + - role: b + tasks: + - name: execute role c which depends on a + import_role: name=c + +- name: play should only show 1 invocation of a, as dependencies in this play are deduped by include_role + hosts: testhost + gather_facts: false + tags: [ 'intasks' ] + tasks: + - name: execute role b which depends on a + include_role: name=b + - name: execute role c which also depends on a + include_role: name=c diff --git a/test/integration/targets/roles/no_outside.yml b/test/integration/targets/roles/no_outside.yml new file mode 100644 index 0000000..cf6fe10 --- /dev/null +++ b/test/integration/targets/roles/no_outside.yml @@ -0,0 +1,7 @@ +- hosts: testhost + gather_facts: false + tasks: + - name: role attempts to load file from outside itself + include_role: + name: a + tasks_from: "{{ playbook_dir }}/tasks/dummy.yml" diff --git a/test/integration/targets/roles/roles/a/tasks/main.yml b/test/integration/targets/roles/roles/a/tasks/main.yml new file mode 100644 index 0000000..7fb1b48 --- /dev/null +++ b/test/integration/targets/roles/roles/a/tasks/main.yml @@ -0,0 +1 @@ +- debug: msg=A diff --git a/test/integration/targets/roles/roles/b/meta/main.yml b/test/integration/targets/roles/roles/b/meta/main.yml new file mode 100644 index 0000000..abe2dd4 --- /dev/null +++ b/test/integration/targets/roles/roles/b/meta/main.yml @@ -0,0 +1,4 @@ +dependencies: + - name: a + +argument_specs: {} diff --git a/test/integration/targets/roles/roles/b/tasks/main.yml b/test/integration/targets/roles/roles/b/tasks/main.yml new file mode 100644 index 0000000..57c1352 --- /dev/null +++ b/test/integration/targets/roles/roles/b/tasks/main.yml @@ -0,0 +1 @@ +- debug: msg=B diff --git a/test/integration/targets/roles/roles/c/meta/main.yml b/test/integration/targets/roles/roles/c/meta/main.yml new file mode 100644 index 0000000..04bd23b --- /dev/null +++ b/test/integration/targets/roles/roles/c/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - name: a diff --git a/test/integration/targets/roles/roles/c/tasks/main.yml b/test/integration/targets/roles/roles/c/tasks/main.yml new file mode 100644 index 0000000..190c429 --- /dev/null +++ b/test/integration/targets/roles/roles/c/tasks/main.yml @@ -0,0 +1 @@ +- debug: msg=C diff --git a/test/integration/targets/roles/roles/data/defaults/main/00.yml b/test/integration/targets/roles/roles/data/defaults/main/00.yml new file mode 100644 index 0000000..98c13a1 --- /dev/null +++ b/test/integration/targets/roles/roles/data/defaults/main/00.yml @@ -0,0 +1 @@ +defined_var: 1 diff --git a/test/integration/targets/roles/roles/data/defaults/main/01.yml b/test/integration/targets/roles/roles/data/defaults/main/01.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/integration/targets/roles/roles/data/defaults/main/01.yml diff --git a/test/integration/targets/roles/roles/data/tasks/main.yml b/test/integration/targets/roles/roles/data/tasks/main.yml new file mode 100644 index 0000000..8d85580 --- /dev/null +++ b/test/integration/targets/roles/roles/data/tasks/main.yml @@ -0,0 +1,5 @@ +- name: ensure data was correctly defind + assert: + that: + - defined_var is defined + - defined_var == 1 diff --git a/test/integration/targets/roles/runme.sh b/test/integration/targets/roles/runme.sh new file mode 100755 index 0000000..bb98a93 --- /dev/null +++ b/test/integration/targets/roles/runme.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -eux + +# test no dupes when dependencies in b and c point to a in roles: +[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags inroles "$@" | grep -c '"msg": "A"')" = "1" ] +[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags acrossroles "$@" | grep -c '"msg": "A"')" = "1" ] +[ "$(ansible-playbook no_dupes.yml -i ../../inventory --tags intasks "$@" | grep -c '"msg": "A"')" = "1" ] + +# but still dupe across plays +[ "$(ansible-playbook no_dupes.yml -i ../../inventory "$@" | grep -c '"msg": "A"')" = "3" ] + +# include/import can execute another instance of role +[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags importrole "$@" | grep -c '"msg": "A"')" = "2" ] +[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags includerole "$@" | grep -c '"msg": "A"')" = "2" ] + + +# ensure role data is merged correctly +ansible-playbook data_integrity.yml -i ../../inventory "$@" + +# ensure role fails when trying to load 'non role' in _from +ansible-playbook no_outside.yml -i ../../inventory "$@" > role_outside_output.log 2>&1 || true +if grep "as it is not inside the expected role path" role_outside_output.log >/dev/null; then + echo "Test passed (playbook failed with expected output, output not shown)." +else + echo "Test failed, expected output from playbook failure is missing, output not shown)." + exit 1 +fi diff --git a/test/integration/targets/roles/tasks/dummy.yml b/test/integration/targets/roles/tasks/dummy.yml new file mode 100644 index 0000000..b168b7a --- /dev/null +++ b/test/integration/targets/roles/tasks/dummy.yml @@ -0,0 +1 @@ +- debug: msg='this should not run' |