file - change warning to error (#66671)

When 'src' is specified without 'state', raise an exception
This commit is contained in:
Sam Doran 2020-01-29 10:51:34 -05:00 committed by GitHub
parent 91063f40d6
commit 9276dd2007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- file - specifying ``src`` without ``state`` is now an error

View file

@ -291,15 +291,10 @@ def additional_parameter_handling(params):
raise ParameterError(results={"msg": "recurse option requires state to be 'directory'",
"path": params["path"]})
# Make sure that src makes sense with the state
# Fail if 'src' but no 'state' is specified
if params['src'] and params['state'] not in ('link', 'hard'):
params['src'] = None
module.warn("The src option requires state to be 'link' or 'hard'. This will become an"
" error in Ansible 2.10")
# In 2.10, switch to this
# raise ParameterError(results={"msg": "src option requires state to be 'link' or 'hard'",
# "path": params["path"]})
raise ParameterError(results={'msg': "src option requires state to be 'link' or 'hard'",
'path': params['path']})
def get_state(path):

View file

@ -345,3 +345,18 @@
- "{{ output_dir }}/test_follow1_link"
# END #56928
# Test failure with src and no state parameter
- name: Specify src without state
file:
src: "{{ output_file }}"
dest: "{{ output_dir }}/link.txt"
ignore_errors: yes
register: src_state
- name: Ensure src without state failed
assert:
that:
- src_state is failed
- "'src option requires state to be' in src_state.msg"