mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
Convert some run_command() string args to lists (#8264)
* Convert some run_command() string args to lists. * Change run_command with pipe and shell to Python code. * Add changelog. * Simplify syntax. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
b48293ca31
commit
70adba8991
14 changed files with 144 additions and 144 deletions
|
@ -68,7 +68,6 @@ EXAMPLES = '''
|
|||
import re
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
|
||||
|
||||
def compare_package(version1, version2):
|
||||
|
@ -94,13 +93,13 @@ def compare_package(version1, version2):
|
|||
def query_package(module, name, depot=None):
|
||||
""" Returns whether a package is installed or not and version. """
|
||||
|
||||
cmd_list = '/usr/sbin/swlist -a revision -l product'
|
||||
cmd_list = ['/usr/sbin/swlist', '-a', 'revision', '-l', 'product']
|
||||
if depot:
|
||||
rc, stdout, stderr = module.run_command("%s -s %s %s | grep %s" % (cmd_list, shlex_quote(depot), shlex_quote(name), shlex_quote(name)),
|
||||
use_unsafe_shell=True)
|
||||
else:
|
||||
rc, stdout, stderr = module.run_command("%s %s | grep %s" % (cmd_list, shlex_quote(name), shlex_quote(name)), use_unsafe_shell=True)
|
||||
cmd_list.extend(['-s', depot])
|
||||
cmd_list.append(name)
|
||||
rc, stdout, stderr = module.run_command(cmd_list)
|
||||
if rc == 0:
|
||||
stdout = ''.join(line for line in stdout.splitlines(True) if name in line)
|
||||
version = re.sub(r"\s\s+|\t", " ", stdout).strip().split()[1]
|
||||
else:
|
||||
version = None
|
||||
|
@ -112,7 +111,7 @@ def remove_package(module, name):
|
|||
""" Uninstall package if installed. """
|
||||
|
||||
cmd_remove = '/usr/sbin/swremove'
|
||||
rc, stdout, stderr = module.run_command("%s %s" % (cmd_remove, name))
|
||||
rc, stdout, stderr = module.run_command([cmd_remove, name])
|
||||
|
||||
if rc == 0:
|
||||
return rc, stdout
|
||||
|
@ -123,8 +122,8 @@ def remove_package(module, name):
|
|||
def install_package(module, depot, name):
|
||||
""" Install package if not already installed """
|
||||
|
||||
cmd_install = '/usr/sbin/swinstall -x mount_all_filesystems=false'
|
||||
rc, stdout, stderr = module.run_command("%s -s %s %s" % (cmd_install, depot, name))
|
||||
cmd_install = ['/usr/sbin/swinstall', '-x', 'mount_all_filesystems=false']
|
||||
rc, stdout, stderr = module.run_command(cmd_install + ["-s", depot, name])
|
||||
if rc == 0:
|
||||
return rc, stdout
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue