mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Do not copy file if running on check mode
This commit is contained in:
parent
0c7ec1e860
commit
259c4b31fb
1 changed files with 28 additions and 27 deletions
|
@ -301,33 +301,34 @@ def main():
|
||||||
|
|
||||||
backup_file = None
|
backup_file = None
|
||||||
if checksum_src != checksum_dest or os.path.islink(dest):
|
if checksum_src != checksum_dest or os.path.islink(dest):
|
||||||
try:
|
if not module.check_mode:
|
||||||
if backup:
|
try:
|
||||||
if os.path.exists(dest):
|
if backup:
|
||||||
backup_file = module.backup_local(dest)
|
if os.path.exists(dest):
|
||||||
# allow for conversion from symlink.
|
backup_file = module.backup_local(dest)
|
||||||
if os.path.islink(dest):
|
# allow for conversion from symlink.
|
||||||
os.unlink(dest)
|
if os.path.islink(dest):
|
||||||
open(dest, 'w').close()
|
os.unlink(dest)
|
||||||
if validate:
|
open(dest, 'w').close()
|
||||||
# if we have a mode, make sure we set it on the temporary
|
if validate:
|
||||||
# file source as some validations may require it
|
# if we have a mode, make sure we set it on the temporary
|
||||||
# FIXME: should we do the same for owner/group here too?
|
# file source as some validations may require it
|
||||||
if mode is not None:
|
# FIXME: should we do the same for owner/group here too?
|
||||||
module.set_mode_if_different(src, mode, False)
|
if mode is not None:
|
||||||
if "%s" not in validate:
|
module.set_mode_if_different(src, mode, False)
|
||||||
module.fail_json(msg="validate must contain %%s: %s" % (validate))
|
if "%s" not in validate:
|
||||||
(rc,out,err) = module.run_command(validate % src)
|
module.fail_json(msg="validate must contain %%s: %s" % (validate))
|
||||||
if rc != 0:
|
(rc,out,err) = module.run_command(validate % src)
|
||||||
module.fail_json(msg="failed to validate", exit_status=rc, stdout=out, stderr=err)
|
if rc != 0:
|
||||||
if remote_src:
|
module.fail_json(msg="failed to validate", exit_status=rc, stdout=out, stderr=err)
|
||||||
_, tmpdest = tempfile.mkstemp(dir=os.path.dirname(dest))
|
if remote_src:
|
||||||
shutil.copy2(src, tmpdest)
|
_, tmpdest = tempfile.mkstemp(dir=os.path.dirname(dest))
|
||||||
module.atomic_move(tmpdest, dest)
|
shutil.copy2(src, tmpdest)
|
||||||
else:
|
module.atomic_move(tmpdest, dest)
|
||||||
module.atomic_move(src, dest)
|
else:
|
||||||
except IOError:
|
module.atomic_move(src, dest)
|
||||||
module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc())
|
except IOError:
|
||||||
|
module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc())
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue