copy action plug-in check mode respects force=no

The copy action accepts force=no, which tells it not to replace an
existing file even if it differs from the source.  The copy action
plug-in wasn't respecting this option when operated in check mode, so it
would report that changes are necessary in check mode even though copy
would make no changes when run normally.

Runner._remote_md5 was changed to make the logic for setting rc perhaps
a little more clear, and to make sure that rc=0 when the file does not
exist.
This commit is contained in:
Dale Sedivec 2013-04-06 21:20:10 -05:00 committed by Michael DeHaan
commit 515fd9e915
3 changed files with 18 additions and 2 deletions

View file

@ -42,6 +42,7 @@ class ActionModule(object):
source = options.get('src', None)
content = options.get('content', None)
dest = options.get('dest', None)
force = utils.boolean(options.get('force', 'yes'))
if (source is None and content is None and not 'first_available_file' in inject) or dest is None:
result=dict(failed=True, msg="src (or content) and dest are required")
@ -105,6 +106,10 @@ class ActionModule(object):
dest = os.path.join(dest, os.path.basename(source))
remote_md5 = self.runner._remote_md5(conn, tmp, dest)
# remote_md5 == '0' would mean that the file does not exist.
if remote_md5 != '0' and not force:
return ReturnData(conn=conn, result=dict(changed=False))
exec_rc = None
if local_md5 != remote_md5: