mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Add force_archive option to archive module to allow archiving and compression of single files (#49429)
* feat: add force_archive option * Fix merge conflicts
This commit is contained in:
parent
8f354ea307
commit
3b8768158f
1 changed files with 29 additions and 3 deletions
|
@ -48,6 +48,13 @@ options:
|
||||||
- Remote absolute path, glob, or list of paths or globs for the file or files to exclude from the archive.
|
- Remote absolute path, glob, or list of paths or globs for the file or files to exclude from the archive.
|
||||||
type: list
|
type: list
|
||||||
version_added: '2.4'
|
version_added: '2.4'
|
||||||
|
force_archive:
|
||||||
|
version_added: '2.8'
|
||||||
|
description:
|
||||||
|
- Allow you to force the module to treat this as an archive even if only a single file is specified.
|
||||||
|
- By default behaviour is maintained. i.e A when a single file is specified it is compressed only (not archived).
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
remove:
|
remove:
|
||||||
description:
|
description:
|
||||||
- Remove any added source files and trees after adding to archive.
|
- Remove any added source files and trees after adding to archive.
|
||||||
|
@ -105,6 +112,19 @@ EXAMPLES = r'''
|
||||||
exclude_path:
|
exclude_path:
|
||||||
- /path/to/foo/ba*
|
- /path/to/foo/ba*
|
||||||
format: bz2
|
format: bz2
|
||||||
|
|
||||||
|
- name: Use gzip to compress a single archive (i.e don't archive it first with tar)
|
||||||
|
archive:
|
||||||
|
path: /path/to/foo/single.file
|
||||||
|
dest: /path/file.gz
|
||||||
|
format: gz
|
||||||
|
|
||||||
|
- name: Create a tar.gz archive of a single file.
|
||||||
|
archive:
|
||||||
|
path: /path/to/foo/single.file
|
||||||
|
dest: /path/file.tar.gz
|
||||||
|
format: gz
|
||||||
|
force_archive: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
@ -180,6 +200,7 @@ def main():
|
||||||
format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'xz', 'zip']),
|
format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'xz', 'zip']),
|
||||||
dest=dict(type='path'),
|
dest=dict(type='path'),
|
||||||
exclude_path=dict(type='list'),
|
exclude_path=dict(type='list'),
|
||||||
|
force_archive=dict(type='bool', default=False),
|
||||||
remove=dict(type='bool', default=False),
|
remove=dict(type='bool', default=False),
|
||||||
),
|
),
|
||||||
add_file_common_args=True,
|
add_file_common_args=True,
|
||||||
|
@ -196,6 +217,7 @@ def main():
|
||||||
expanded_paths = []
|
expanded_paths = []
|
||||||
expanded_exclude_paths = []
|
expanded_exclude_paths = []
|
||||||
format = params['format']
|
format = params['format']
|
||||||
|
force_archive = params['force_archive']
|
||||||
globby = False
|
globby = False
|
||||||
changed = False
|
changed = False
|
||||||
state = 'absent'
|
state = 'absent'
|
||||||
|
@ -242,9 +264,13 @@ def main():
|
||||||
if not expanded_paths:
|
if not expanded_paths:
|
||||||
return module.fail_json(path=', '.join(paths), expanded_paths=', '.join(expanded_paths), msg='Error, no source paths were found')
|
return 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
|
# Only try to determine if we are working with an archive or not if we haven't set archive to true
|
||||||
# treat this as a multi-file archive
|
if not force_archive:
|
||||||
archive = globby or os.path.isdir(expanded_paths[0]) or len(expanded_paths) > 1
|
# If we actually matched multiple files or TRIED to, then
|
||||||
|
# treat this as a multi-file archive
|
||||||
|
archive = globby or os.path.isdir(expanded_paths[0]) or len(expanded_paths) > 1
|
||||||
|
else:
|
||||||
|
archive = True
|
||||||
|
|
||||||
# Default created file name (for single-file archives) to
|
# Default created file name (for single-file archives) to
|
||||||
# <file>.<format>
|
# <file>.<format>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue