Handle unreachable errors in fetch properly. Fixes #27816 (#80952)

pull/80983/head
Matt Martz 1 year ago committed by GitHub
parent 5e550b6086
commit aa67d544fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- fetch - Handle unreachable errors properly (https://github.com/ansible/ansible/issues/27816)

@ -19,7 +19,7 @@ __metaclass__ = type
import os
import base64
from ansible.errors import AnsibleError, AnsibleActionFail, AnsibleActionSkip
from ansible.errors import AnsibleConnectionFailure, AnsibleError, AnsibleActionFail, AnsibleActionSkip
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible.module_utils.six import string_types
from ansible.module_utils.parsing.convert_bool import boolean
@ -75,6 +75,8 @@ class ActionModule(ActionBase):
# Follow symlinks because fetch always follows symlinks
try:
remote_stat = self._execute_remote_stat(source, all_vars=task_vars, follow=True)
except AnsibleConnectionFailure:
raise
except AnsibleError as ae:
result['changed'] = False
result['file'] = source

@ -28,6 +28,15 @@
register: failed_fetch_dest_dir
ignore_errors: true
- name: Test unreachable
fetch:
src: "{{ remote_tmp_dir }}/orig"
dest: "{{ output_dir }}"
register: unreachable_fetch
ignore_unreachable: true
vars:
ansible_user: wrong
- name: Ensure fetch failed
assert:
that:
@ -39,3 +48,4 @@
- failed_fetch_no_access.msg is search('file is not readable')
- failed_fetch_dest_dir is failed
- failed_fetch_dest_dir.msg is search('dest is an existing directory')
- unreachable_fetch is unreachable

Loading…
Cancel
Save