From b06353791c70ce714cc6d7e3b18cb27174b4ee2b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 23 Jul 2015 00:39:15 -0700 Subject: [PATCH] Don't pass mode from synchronize action plugin to the ansible module Fixes https://github.com/ansible/ansible-modules-core/issues/1783 --- lib/ansible/plugins/action/synchronize.py | 5 + .../roles/test_synchronize/tasks/main.yml | 120 +++++++++++++++++- 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index 1da3db50ab5..ec1f938ffce 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -169,6 +169,11 @@ class ActionModule(ActionBase): if use_ssh_args: self._task.args['ssh_args'] = constants.ANSIBLE_SSH_ARGS + # Remove mode as it is handled purely in this action module + if 'mode' in self._task.args: + del self._task.args['mode'] + + # run the module and store the result result = self._execute_module('synchronize', task_vars=task_vars) diff --git a/test/integration/roles/test_synchronize/tasks/main.yml b/test/integration/roles/test_synchronize/tasks/main.yml index 85622b74191..b3aa83922f0 100644 --- a/test/integration/roles/test_synchronize/tasks/main.yml +++ b/test/integration/roles/test_synchronize/tasks/main.yml @@ -40,6 +40,124 @@ - "sync_result.msg.startswith('>f+')" - "sync_result.msg.endswith('+ foo.txt\n')" +- name: test that the file was really copied over + stat: + path: "{{ output_dir }}/foo.result" + register: stat_result + +- assert: + that: + - "stat_result.stat.exists == True" + - "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'" + +- name: test that the file is not copied a second time + synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.result + register: sync_result + +- assert: + that: + - "sync_result.changed == False" + +- name: Cleanup + file: + state: absent + path: "{{output_dir}}/{{item}}" + with_items: + - foo.result + - bar.result + +- name: Synchronize using the mode=push param + synchronize: + src: "{{output_dir}}/foo.txt" + dest: "{{output_dir}}/foo.result" + mode: push + register: sync_result + +- assert: + that: + - "'changed' in sync_result" + - "sync_result.changed == true" + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'msg' in sync_result" + - "sync_result.msg.startswith('>f+')" + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: test that the file was really copied over + stat: + path: "{{ output_dir }}/foo.result" + register: stat_result + +- assert: + that: + - "stat_result.stat.exists == True" + - "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'" + +- name: test that the file is not copied a second time + synchronize: + src: "{{output_dir}}/foo.txt" + dest: "{{output_dir}}/foo.result" + mode: push + register: sync_result + +- assert: + that: + - "sync_result.changed == False" + +- name: Cleanup + file: + state: absent + path: "{{output_dir}}/{{item}}" + with_items: + - foo.result + - bar.result + +- name: Synchronize using the mode=pull param + synchronize: + src: "{{output_dir}}/foo.txt" + dest: "{{output_dir}}/foo.result" + mode: pull + register: sync_result + +- assert: + that: + - "'changed' in sync_result" + - "sync_result.changed == true" + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'msg' in sync_result" + - "sync_result.msg.startswith('>f+')" + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: test that the file was really copied over + stat: + path: "{{ output_dir }}/foo.result" + register: stat_result + +- assert: + that: + - "stat_result.stat.exists == True" + - "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'" + +- name: test that the file is not copied a second time + synchronize: + src: "{{output_dir}}/foo.txt" + dest: "{{output_dir}}/foo.result" + mode: pull + register: sync_result + +- assert: + that: + - "sync_result.changed == False" + +- name: Cleanup + file: + state: absent + path: "{{output_dir}}/{{item}}" + with_items: + - foo.result + - bar.result + - name: synchronize files using with_items (issue#5965) synchronize: src={{output_dir}}/{{item}} dest={{output_dir}}/{{item}}.result with_items: @@ -47,7 +165,6 @@ - bar.txt register: sync_result -- debug: var=sync_result - assert: that: - "sync_result.changed" @@ -61,7 +178,6 @@ synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.rsync_path rsync_path="sudo rsync" register: sync_result -- debug: var=sync_result - assert: that: - "'changed' in sync_result"