Accept 'path' as a list argument, expose path and expanded_path,

Use correct variable in expanduser
pull/18777/head
Ben Doherty 9 years ago committed by Matt Clay
parent 2aa3f52bf3
commit c5b9bda656

@ -110,7 +110,7 @@ import tarfile
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
path = dict(required=True), path = dict(type='list', required=True),
compression = dict(choices=['gz', 'bz2', 'zip'], default='gz', required=False), compression = dict(choices=['gz', 'bz2', 'zip'], default='gz', required=False),
creates = dict(required=False), creates = dict(required=False),
remove = dict(required=False, default=True, type='bool'), remove = dict(required=False, default=True, type='bool'),
@ -133,11 +133,8 @@ def main():
archive = False archive = False
successes = [] successes = []
if isinstance(paths, basestring):
paths = [paths]
for i, path in enumerate(paths): for i, path in enumerate(paths):
path = os.path.expanduser(params['path']) path = os.path.expanduser(path)
# Detect glob-like characters # Detect glob-like characters
if any((c in set('*?')) for c in path): if any((c in set('*?')) for c in path):
@ -146,7 +143,7 @@ def main():
expanded_paths.append(path) expanded_paths.append(path)
if len(expanded_paths) == 0: if len(expanded_paths) == 0:
module.fail_json(path, msg='Error, no source paths were found') module.fail_json(path=', '.join(paths), expanded_paths=', '.join(expanded_paths), msg='Error, no source paths were found')
# If we actually matched multiple files or TRIED to, then # If we actually matched multiple files or TRIED to, then
# treat this as a multi-file archive # treat this as a multi-file archive
@ -170,7 +167,7 @@ def main():
# Use the longest common directory name among all the files # Use the longest common directory name among all the files
# as the archive root path # as the archive root path
if arcroot == '': if arcroot == '':
arcroot = os.path.dirname(path) arcroot = os.path.dirname(path) + os.sep
else: else:
for i in xrange(len(arcroot)): for i in xrange(len(arcroot)):
if path[i] != arcroot[i]: if path[i] != arcroot[i]:
@ -259,8 +256,7 @@ def main():
archive.close() archive.close()
state = 'archive' state = 'archive'
if state in ['archive', 'incomplete'] and remove:
if state == 'archive' and remove:
for path in successes: for path in successes:
try: try:
if os.path.isdir(path): if os.path.isdir(path):

Loading…
Cancel
Save