mirror of https://github.com/ansible/ansible.git
New keyword: ignore_unreachable (#43857)
parent
2603604fd6
commit
653d9c0f87
@ -0,0 +1,2 @@
|
|||||||
|
major_changes:
|
||||||
|
- New keyword `ignore_unreachable` for plays and blocks. Allows ignoring tasks that fail due to unreachable hosts, and check results with `is unreachable` test.
|
@ -0,0 +1 @@
|
|||||||
|
shippable/posix/group3
|
@ -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')
|
@ -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')
|
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
- prepare_tests
|
@ -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
|
@ -0,0 +1,5 @@
|
|||||||
|
- hosts: [localhost, nonexistent]
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Hi
|
||||||
|
ping:
|
@ -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)'
|
@ -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:
|
Loading…
Reference in New Issue