From cc9c72d6f845710b24e952670b534a57f6948513 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Fri, 22 Feb 2019 19:48:44 -0500 Subject: [PATCH] Do not add state: absent when a non-existent path is returned (#51350) 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 --- .../fragments/basic-no-state-absent-when-path-or-dest.yaml | 2 ++ lib/ansible/module_utils/basic.py | 2 -- lib/ansible/modules/files/file.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/basic-no-state-absent-when-path-or-dest.yaml diff --git a/changelogs/fragments/basic-no-state-absent-when-path-or-dest.yaml b/changelogs/fragments/basic-no-state-absent-when-path-or-dest.yaml new file mode 100644 index 00000000000000..110f7fb3aba947 --- /dev/null +++ b/changelogs/fragments/basic-no-state-absent-when-path-or-dest.yaml @@ -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)' diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index eb7c77f50b11a8..9901f77196ea09 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -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): diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py index ca12a7ec9a0ff2..1d7d38cfa99e8e 100644 --- a/lib/ansible/modules/files/file.py +++ b/lib/ansible/modules/files/file.py @@ -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