New keyword: ignore_unreachable (#43857)

This commit is contained in:
jctanner
2018-08-23 11:41:02 -04:00
committed by Ryan Brown
parent 2603604fd6
commit 653d9c0f87
15 changed files with 129 additions and 2 deletions

View File

@@ -0,0 +1 @@
shippable/posix/group3

View File

@@ -0,0 +1,11 @@
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')

View File

@@ -0,0 +1,11 @@
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')

View File

@@ -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

View File

@@ -0,0 +1,2 @@
dependencies:
- prepare_tests

View File

@@ -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

View File

@@ -0,0 +1,5 @@
- hosts: [localhost, nonexistent]
gather_facts: false
tasks:
- name: Hi
ping:

View File

@@ -0,0 +1,30 @@
---
- hosts: localhost
connection: local
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)'

View File

@@ -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:

View File

@@ -269,6 +269,7 @@ class TestStrategyBase(unittest.TestCase):
mock_task._role = None
mock_task._parent = None
mock_task.ignore_errors = False
mock_task.ignore_unreachable = False
mock_task._uuid = uuid.uuid4()
mock_task.loop = None
mock_task.copy.return_value = mock_task