diff options
Diffstat (limited to 'test/integration/targets/infra')
-rw-r--r-- | test/integration/targets/infra/aliases | 3 | ||||
-rw-r--r-- | test/integration/targets/infra/inventory.local | 2 | ||||
-rw-r--r-- | test/integration/targets/infra/library/test.py | 21 | ||||
-rwxr-xr-x | test/integration/targets/infra/runme.sh | 39 | ||||
-rw-r--r-- | test/integration/targets/infra/test_test_infra.yml | 25 |
5 files changed, 90 insertions, 0 deletions
diff --git a/test/integration/targets/infra/aliases b/test/integration/targets/infra/aliases new file mode 100644 index 00000000..887d7029 --- /dev/null +++ b/test/integration/targets/infra/aliases @@ -0,0 +1,3 @@ +shippable/posix/group3 +needs/file/hacking/test-module.py +needs/file/lib/ansible/modules/ping.py diff --git a/test/integration/targets/infra/inventory.local b/test/integration/targets/infra/inventory.local new file mode 100644 index 00000000..2baa1f88 --- /dev/null +++ b/test/integration/targets/infra/inventory.local @@ -0,0 +1,2 @@ +testhost ansible_connection=local + diff --git a/test/integration/targets/infra/library/test.py b/test/integration/targets/infra/library/test.py new file mode 100644 index 00000000..93860575 --- /dev/null +++ b/test/integration/targets/infra/library/test.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict(), + ) + result = { + 'selinux_special_fs': module._selinux_special_fs, + 'tmpdir': module._tmpdir, + 'keep_remote_files': module._keep_remote_files, + 'version': module.ansible_version, + } + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/infra/runme.sh b/test/integration/targets/infra/runme.sh new file mode 100755 index 00000000..c4d84572 --- /dev/null +++ b/test/integration/targets/infra/runme.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -ux + +# ensure fail/assert work locally and can stop execution with non-zero exit code +PB_OUT=$(ansible-playbook -i inventory.local test_test_infra.yml) +APB_RC=$? +echo "$PB_OUT" +echo "rc was $APB_RC (must be non-zero)" +[ ${APB_RC} -ne 0 ] +echo "ensure playbook output shows assert/fail works (True)" +echo "$PB_OUT" | grep -F "fail works (True)" || exit 1 +echo "$PB_OUT" | grep -F "assert works (True)" || exit 1 + +# ensure we work using all specified test args, overridden inventory, etc +PB_OUT=$(ansible-playbook -i ../../inventory test_test_infra.yml "$@") +APB_RC=$? +echo "$PB_OUT" +echo "rc was $APB_RC (must be non-zero)" +[ ${APB_RC} -ne 0 ] +echo "ensure playbook output shows assert/fail works (True)" +echo "$PB_OUT" | grep -F "fail works (True)" || exit 1 +echo "$PB_OUT" | grep -F "assert works (True)" || exit 1 + +set -e + +PING_MODULE_PATH="../../../../lib/ansible/modules/ping.py" + +# ensure test-module.py script works without passing Python interpreter path +../../../../hacking/test-module.py -m "$PING_MODULE_PATH" + +# ensure test-module.py script works well +../../../../hacking/test-module.py -m "$PING_MODULE_PATH" -I ansible_python_interpreter="$(which python)" + +# ensure module.ansible_version is defined when using test-module.py +../../../../hacking/test-module.py -m library/test.py -I ansible_python_interpreter="$(which python)" <<< '{"ANSIBLE_MODULE_ARGS": {}}' + +# ensure exercising module code locally works +python -m ansible.modules.file <<< '{"ANSIBLE_MODULE_ARGS": {"path": "/path/to/file", "state": "absent"}}' diff --git a/test/integration/targets/infra/test_test_infra.yml b/test/integration/targets/infra/test_test_infra.yml new file mode 100644 index 00000000..706f9b8f --- /dev/null +++ b/test/integration/targets/infra/test_test_infra.yml @@ -0,0 +1,25 @@ +- hosts: testhost + gather_facts: no + tags: + - always + tasks: + - name: ensure fail action produces a failing result + fail: + ignore_errors: yes + register: fail_out + + - debug: + msg: fail works ({{ fail_out.failed }}) + + - name: ensure assert produces a failing result + assert: + that: false + ignore_errors: yes + register: assert_out + + - debug: + msg: assert works ({{ assert_out.failed }}) + + - name: EXPECTED FAILURE ensure fail action stops execution + fail: + msg: fail actually failed (this is expected) |