diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/ignore_unreachable | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream.tar.xz ansible-core-upstream.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/ignore_unreachable')
9 files changed, 109 insertions, 0 deletions
diff --git a/test/integration/targets/ignore_unreachable/aliases b/test/integration/targets/ignore_unreachable/aliases new file mode 100644 index 0000000..1d28bdb --- /dev/null +++ b/test/integration/targets/ignore_unreachable/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +context/controller diff --git a/test/integration/targets/ignore_unreachable/fake_connectors/bad_exec.py b/test/integration/targets/ignore_unreachable/fake_connectors/bad_exec.py new file mode 100644 index 0000000..0d8c385 --- /dev/null +++ b/test/integration/targets/ignore_unreachable/fake_connectors/bad_exec.py @@ -0,0 +1,14 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import ansible.plugins.connection.local as ansible_local +from ansible.errors import AnsibleConnectionFailure + +from ansible.utils.display import Display +display = Display() + + +class Connection(ansible_local.Connection): + def exec_command(self, cmd, in_data=None, sudoable=True): + display.debug('Intercepted call to exec remote command') + raise AnsibleConnectionFailure('BADLOCAL Error: this is supposed to fail') diff --git a/test/integration/targets/ignore_unreachable/fake_connectors/bad_put_file.py b/test/integration/targets/ignore_unreachable/fake_connectors/bad_put_file.py new file mode 100644 index 0000000..d4131f4 --- /dev/null +++ b/test/integration/targets/ignore_unreachable/fake_connectors/bad_put_file.py @@ -0,0 +1,14 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import ansible.plugins.connection.local as ansible_local +from ansible.errors import AnsibleConnectionFailure + +from ansible.utils.display import Display +display = Display() + + +class Connection(ansible_local.Connection): + def put_file(self, in_path, out_path): + display.debug('Intercepted call to send data') + raise AnsibleConnectionFailure('BADLOCAL Error: this is supposed to fail') diff --git a/test/integration/targets/ignore_unreachable/inventory b/test/integration/targets/ignore_unreachable/inventory new file mode 100644 index 0000000..495a68c --- /dev/null +++ b/test/integration/targets/ignore_unreachable/inventory @@ -0,0 +1,3 @@ +nonexistent ansible_host=169.254.199.200 +bad_put_file ansible_host=localhost ansible_connection=bad_put_file +bad_exec ansible_host=localhost ansible_connection=bad_exec diff --git a/test/integration/targets/ignore_unreachable/meta/main.yml b/test/integration/targets/ignore_unreachable/meta/main.yml new file mode 100644 index 0000000..07faa21 --- /dev/null +++ b/test/integration/targets/ignore_unreachable/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_tests diff --git a/test/integration/targets/ignore_unreachable/runme.sh b/test/integration/targets/ignore_unreachable/runme.sh new file mode 100755 index 0000000..5b0ef19 --- /dev/null +++ b/test/integration/targets/ignore_unreachable/runme.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -eux + +export ANSIBLE_CONNECTION_PLUGINS=./fake_connectors +# use fake connectors that raise srrors at different stages +ansible-playbook test_with_bad_plugins.yml -i inventory -v "$@" +unset ANSIBLE_CONNECTION_PLUGINS + +ansible-playbook test_cannot_connect.yml -i inventory -v "$@" + +if ansible-playbook test_base_cannot_connect.yml -i inventory -v "$@"; then + echo "Playbook intended to fail succeeded. Connection succeeded to nonexistent host" + exit 99 +else + echo "Connection to nonexistent hosts failed without using ignore_unreachable. Success!" +fi diff --git a/test/integration/targets/ignore_unreachable/test_base_cannot_connect.yml b/test/integration/targets/ignore_unreachable/test_base_cannot_connect.yml new file mode 100644 index 0000000..931c82b --- /dev/null +++ b/test/integration/targets/ignore_unreachable/test_base_cannot_connect.yml @@ -0,0 +1,5 @@ +- hosts: [localhost, nonexistent] + gather_facts: false + tasks: + - name: Hi + ping: diff --git a/test/integration/targets/ignore_unreachable/test_cannot_connect.yml b/test/integration/targets/ignore_unreachable/test_cannot_connect.yml new file mode 100644 index 0000000..64e2bfe --- /dev/null +++ b/test/integration/targets/ignore_unreachable/test_cannot_connect.yml @@ -0,0 +1,29 @@ +--- +- hosts: localhost + gather_facts: false + tasks: + - name: Hi + ping: +- hosts: [localhost, nonexistent] + ignore_unreachable: true + gather_facts: false + tasks: + - name: Hi + ping: +- hosts: nonexistent + ignore_unreachable: true + gather_facts: false + tasks: + - name: Hi + ping: + - name: This should print anyway + debug: + msg: This should print worked even though host was unreachable + - name: Hi + ping: + register: should_fail + - assert: + that: + - 'should_fail is unreachable' + - 'not (should_fail is skipped)' + - 'not (should_fail is failed)' diff --git a/test/integration/targets/ignore_unreachable/test_with_bad_plugins.yml b/test/integration/targets/ignore_unreachable/test_with_bad_plugins.yml new file mode 100644 index 0000000..5d62f19 --- /dev/null +++ b/test/integration/targets/ignore_unreachable/test_with_bad_plugins.yml @@ -0,0 +1,24 @@ +- hosts: bad_put_file + gather_facts: false + ignore_unreachable: true + tasks: + - name: Hi + ping: +- hosts: bad_put_file + gather_facts: true + ignore_unreachable: true + tasks: + - name: Hi + ping: +- hosts: bad_exec + gather_facts: false + ignore_unreachable: true + tasks: + - name: Hi + ping: +- hosts: bad_exec + gather_facts: true + ignore_unreachable: true + tasks: + - name: Hi + ping: |