From 99bf89447b0ca6090185f124a23070dbdecfedd9 Mon Sep 17 00:00:00 2001 From: Justin Findlay Date: Wed, 28 Sep 2016 12:50:44 -0600 Subject: [PATCH] modules.archive: add opts arg to g(un)zip --- salt/modules/archive.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/salt/modules/archive.py b/salt/modules/archive.py index c3c77863af..7c412271dd 100644 --- a/salt/modules/archive.py +++ b/salt/modules/archive.py @@ -132,7 +132,7 @@ def tar(options, tarfile, sources=None, dest=None, @salt.utils.decorators.which('gzip') -def gzip(sourcefile, template=None, runas=None): +def gzip(sourcefile, template=None, runas=None, options=None): ''' Uses the gzip command to create gzip files @@ -144,14 +144,27 @@ def gzip(sourcefile, template=None, runas=None): salt '*' archive.gzip template=jinja /tmp/{{grains.id}}.txt + runas : None + The user with which to run the gzip command line + + options : None + Pass any additional arguments to gzip + + .. versionadded:: 2016.3.4 + CLI Example: .. code-block:: bash # Create /tmp/sourcefile.txt.gz salt '*' archive.gzip /tmp/sourcefile.txt + salt '*' archive.gzip /tmp/sourcefile.txt options='-9 --verbose' ''' - cmd = ['gzip', '{0}'.format(sourcefile)] + cmd = ['gzip'] + if options: + cmd.append(options) + cmd.append('{0}'.format(sourcefile)) + return __salt__['cmd.run'](cmd, template=template, runas=runas, @@ -159,7 +172,7 @@ def gzip(sourcefile, template=None, runas=None): @salt.utils.decorators.which('gunzip') -def gunzip(gzipfile, template=None, runas=None): +def gunzip(gzipfile, template=None, runas=None, options=None): ''' Uses the gunzip command to unpack gzip files @@ -171,14 +184,27 @@ def gunzip(gzipfile, template=None, runas=None): salt '*' archive.gunzip template=jinja /tmp/{{grains.id}}.txt.gz + runas : None + The user with which to run the gzip command line + + options : None + Pass any additional arguments to gzip + + .. versionadded:: 2016.3.4 + CLI Example: .. code-block:: bash # Create /tmp/sourcefile.txt salt '*' archive.gunzip /tmp/sourcefile.txt.gz + salt '*' archive.gunzip /tmp/sourcefile.txt options='--verbose' ''' - cmd = ['gunzip', '{0}'.format(gzipfile)] + cmd = ['gunzip'] + if options: + cmd.append(options) + cmd.append('{0}'.format(gzipfile)) + return __salt__['cmd.run'](cmd, template=template, runas=runas,