summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien <juju4@users.noreply.github.com>2020-07-15 12:40:25 -0400
committerGitHub <noreply@github.com>2020-07-15 12:40:25 -0400
commit57b548598c07afda1db9e0c79dca019114a6e392 (patch)
tree5f4f1fd0da307054b048a240938684fe3d180aa2
parente1a33a6a84774c568285e0b6090655e1473fbef7 (diff)
downloadansible-57b548598c07afda1db9e0c79dca019114a6e392.tar.gz
add alpine apk package manager to package_facts [wip] (#70587)
* add alpine apk package manager to package_facts
-rw-r--r--changelogs/fragments/70587-package_facts-apk.yml2
-rw-r--r--lib/ansible/modules/package_facts.py25
2 files changed, 26 insertions, 1 deletions
diff --git a/changelogs/fragments/70587-package_facts-apk.yml b/changelogs/fragments/70587-package_facts-apk.yml
new file mode 100644
index 0000000000..68a0a313e7
--- /dev/null
+++ b/changelogs/fragments/70587-package_facts-apk.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - add support for alpine linux 'apk' package manager in package_facts
diff --git a/lib/ansible/modules/package_facts.py b/lib/ansible/modules/package_facts.py
index e957e8300b..255ab5f09a 100644
--- a/lib/ansible/modules/package_facts.py
+++ b/lib/ansible/modules/package_facts.py
@@ -19,8 +19,9 @@ options:
- The package manager used by the system so we can query the package information.
- Since 2.8 this is a list and can support multiple package managers per system.
- The 'portage' and 'pkg' options were added in version 2.8.
+ - The 'apk' option was added in version 2.11.
default: ['auto']
- choices: ['auto', 'rpm', 'apt', 'portage', 'pkg', 'pacman']
+ choices: ['auto', 'rpm', 'apt', 'portage', 'pkg', 'pacman', 'apk']
required: False
type: list
strategy:
@@ -376,6 +377,28 @@ class PORTAGE(CLIMgr):
return dict(zip(self.atoms, package.split()))
+class APK(CLIMgr):
+
+ CLI = 'apk'
+ atoms = ['name', 'version']
+
+ def list_installed(self):
+ rc, out, err = module.run_command([self._cli, 'info', '-v'])
+ if rc != 0 or err:
+ raise Exception("Unable to list packages rc=%s : %s" % (rc, err))
+ return out.splitlines()
+
+ def get_package_details(self, package):
+ raw_pkg_details = {}
+ for line in package.splitlines():
+ m = re.match(r"([\w ].*?)-([0-9-\.]+[0-9a-z-\.]*-r[0-9]+)", to_native(line))
+ if m:
+ raw_pkg_details['name'] = m.group(1)
+ raw_pkg_details['version'] = m.group(2)
+
+ return raw_pkg_details
+
+
def main():
# get supported pkg managers