Move backup to module_common

This commit is contained in:
Daniel Hokka Zakrisson 2012-09-04 14:16:30 +02:00
parent 7c2fe3da16
commit dfcb9d3c2d
2 changed files with 15 additions and 18 deletions

View file

@ -47,6 +47,8 @@ import subprocess
import sys
import syslog
import types
import time
import shutil
try:
from hashlib import md5 as _md5
@ -274,6 +276,18 @@ class AnsibleModule(object):
infile.close()
return digest.hexdigest()
def backuplocal(self, fn):
'''make a date-marked backup of the specified file, return True or False on success or failure'''
# backups named basename-YYYY-MM-DD@HH:MM~
ext = time.strftime("%Y-%m-%d@%H:%M~", time.localtime(time.time()))
backupdest = '%s.%s' % (fn, ext)
try:
shutil.copy2(fn, backupdest)
except shutil.Error, e:
self.fail_json(msg='Could not make backup of %s to %s: %s' % (fn, backupdest, e))
return backupdest
# == END DYNAMICALLY INSERTED CODE ===