file - return 'state': 'absent' when a file does not exist (#66503)

This was changed in ansible/ansible#51350.
pull/69659/head
Sam Doran 5 years ago committed by GitHub
parent e0f25a2b1f
commit cd8920af99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- "file - return ``'state': 'absent'`` when a file does not exist (https://github.com/ansible/ansible/issues/66171)"

@ -583,7 +583,7 @@ def ensure_file_attributes(path, follow, timestamps):
if prev_state not in ('file', 'hard'):
# file is not absent and any other state is a conflict
raise AnsibleModuleError(results={'msg': 'file (%s) is %s, cannot continue' % (path, prev_state),
'path': path})
'path': path, 'state': prev_state})
diff = initial_diff(path, 'file', prev_state)
changed = module.set_fs_attributes_if_different(file_args, False, diff, expand=False)

@ -61,6 +61,25 @@
- "file_result.changed == false"
- "file_result.state == 'file'"
- name: Make sure file does not exist
file:
path: /tmp/ghost
state: absent
- name: Target a file that does not exist
file:
path: /tmp/ghost
ignore_errors: yes
register: ghost_file_result
- name: Validate ghost file results
assert:
that:
- ghost_file_result is failed
- ghost_file_result is not changed
- ghost_file_result.state == 'absent'
- "'cannot continue' in ghost_file_result.msg"
- name: verify that we are checking an absent file
file: path={{output_dir}}/bar.txt state=absent
register: file2_result
@ -269,7 +288,7 @@
copy: src=foobar dest={{output_dir}}
- name: check what would be removed if folder state was absent and diff is enabled
file:
file:
path: "{{ item }}"
state: absent
check_mode: yes

Loading…
Cancel
Save