Skip to content

Commit

Permalink
Do not add state: absent when a non-existent path is returned (#51350)
Browse files Browse the repository at this point in the history
Leave it up to the module to return the state in the results.

I went through all the modules in files/ and only found one case where the module needed to return this. No other modules return paths that do not exists.

Signed-off-by: Sam Doran <sdoran@redhat.com>
  • Loading branch information
samdoran authored and dagwieers committed Feb 23, 2019
1 parent d65a91e commit cc9c72d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- 'do not return ``state: absent`` when the module returns either ``path`` or ``dest`` but the file does not exists (https://github.com/ansible/ansible/issues/35382)'
2 changes: 0 additions & 2 deletions lib/ansible/module_utils/basic.py
Expand Up @@ -1559,8 +1559,6 @@ def add_path_info(self, kwargs):
if HAVE_SELINUX and self.selinux_enabled():
kwargs['secontext'] = ':'.join(self.selinux_context(path))
kwargs['size'] = st[stat.ST_SIZE]
else:
kwargs['state'] = 'absent'
return kwargs

def _check_locale(self):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/files/file.py
Expand Up @@ -470,9 +470,9 @@ def ensure_absent(path):
'path': path})

diff = initial_diff(path, 'absent', prev_state)
result.update({'path': path, 'changed': True, 'diff': diff})
result.update({'path': path, 'changed': True, 'diff': diff, 'state': 'absent'})
else:
result.update({'path': path, 'changed': False})
result.update({'path': path, 'changed': False, 'state': 'absent'})

return result

Expand Down

0 comments on commit cc9c72d

Please sign in to comment.