summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2020-02-10 17:07:07 -0500
committerGitHub <noreply@github.com>2020-02-10 14:07:07 -0800
commitc4f1e04bef6024341fb5c878cc90b79e50c0af64 (patch)
tree22179a2cdc9752545f856edca9ca9bfb277ef61d
parent3284262a60adcad318a889270830036306fa0a21 (diff)
downloadansible-c4f1e04bef6024341fb5c878cc90b79e50c0af64.tar.gz
[stable-2.9] file - change _diff_peek type in argument_spec (#60428) (#66587)
* Add integration tests * Handle error in _get_diff_data() * Change to warning rather than error * Also change failure to warning in assemble action plugin (cherry picked from commit 9b7198d25e) Co-authored-by: Sam Doran <sdoran@redhat.com>
-rw-r--r--changelogs/fragments/file-fix-diff-peek-arg-spec.yaml2
-rw-r--r--lib/ansible/modules/files/file.py2
-rw-r--r--lib/ansible/plugins/action/__init__.py6
-rw-r--r--test/integration/targets/file/tasks/diff_peek.yml10
-rw-r--r--test/integration/targets/file/tasks/main.yml16
5 files changed, 28 insertions, 8 deletions
diff --git a/changelogs/fragments/file-fix-diff-peek-arg-spec.yaml b/changelogs/fragments/file-fix-diff-peek-arg-spec.yaml
new file mode 100644
index 0000000000..de3cc4b5d6
--- /dev/null
+++ b/changelogs/fragments/file-fix-diff-peek-arg-spec.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - file - change ``_diff_peek`` in argument spec to be the correct type, which is ``bool`` (https://github.com/ansible/ansible/issues/59433)
diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py
index 575f3c7d27..33a61516bf 100644
--- a/lib/ansible/modules/files/file.py
+++ b/lib/ansible/modules/files/file.py
@@ -886,7 +886,7 @@ def main():
recurse=dict(type='bool', default=False),
force=dict(type='bool', default=False), # Note: Should not be in file_common_args in future
follow=dict(type='bool', default=True), # Note: Different default than file_common_args
- _diff_peek=dict(type='str'), # Internal use only, for internal checks in the action plugins
+ _diff_peek=dict(type='bool'), # Internal use only, for internal checks in the action plugins
src=dict(type='path'), # Note: Should not be in file_common_args in future
modification_time=dict(type='str'),
modification_time_format=dict(type='str', default='%Y%m%d%H%M.%S'),
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index dc72e6c56c..1b8689dbe9 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -1110,7 +1110,11 @@ class ActionBase(with_metaclass(ABCMeta, object)):
display.debug("Going to peek to see if file has changed permissions")
peek_result = self._execute_module(module_name='file', module_args=dict(path=destination, _diff_peek=True), task_vars=task_vars, persist_files=True)
- if not peek_result.get('failed', False) or peek_result.get('rc', 0) == 0:
+ if peek_result.get('failed', False):
+ display.warning(u"Failed to get diff between '%s' and '%s': %s" % (os.path.basename(source), destination, to_text(peek_result.get(u'msg', u''))))
+ return diff
+
+ if peek_result.get('rc', 0) == 0:
if peek_result.get('state') in (None, 'absent'):
diff['before'] = u''
diff --git a/test/integration/targets/file/tasks/diff_peek.yml b/test/integration/targets/file/tasks/diff_peek.yml
new file mode 100644
index 0000000000..802a99aaba
--- /dev/null
+++ b/test/integration/targets/file/tasks/diff_peek.yml
@@ -0,0 +1,10 @@
+- name: Run task with _diff_peek
+ file:
+ path: "{{ output_file }}"
+ _diff_peek: yes
+ register: diff_peek_result
+
+- name: Ensure warning was not issued when using _diff_peek parameter
+ assert:
+ that:
+ - diff_peek_result['warnings'] is not defined
diff --git a/test/integration/targets/file/tasks/main.yml b/test/integration/targets/file/tasks/main.yml
index f957812c2d..8731c55474 100644
--- a/test/integration/targets/file/tasks/main.yml
+++ b/test/integration/targets/file/tasks/main.yml
@@ -25,25 +25,29 @@
- set_fact:
remote_file_expanded: '{{ echo.stdout }}'
-# Include the tests
+# Import the test tasks
- name: Run tests for state=link
- include: state_link.yml
+ import_tasks: state_link.yml
- name: Run tests for directory as dest
- include: directory_as_dest.yml
+ import_tasks: directory_as_dest.yml
- name: Run tests for unicode
- include: unicode_path.yml
+ import_tasks: unicode_path.yml
environment:
LC_ALL: C
LANG: C
- name: decide to include or not include selinux tests
- include: selinux_tests.yml
+ include_tasks: selinux_tests.yml
when: selinux_installed is defined and selinux_installed.stdout != "" and selinux_enabled.stdout != "Disabled"
- name: Initialize the test output dir
- include: initialize.yml
+ import_tasks: initialize.yml
+
+- name: Test _diff_peek
+ import_tasks: diff_peek.yml
+
# These tests need to be organized by state parameter into separate files later