package_facts: Support pkg_info OpenBSD, FreeBSD and NetBSD (#76580)

pull/76688/head
Romain Goncalves 2 years ago committed by GitHub
parent 0502a03579
commit b984dd9c59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- package_facts - add pkg_info support for OpenBSD and NetBSD (https://github.com/ansible/ansible/pull/76580)

@ -19,8 +19,9 @@ options:
- 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.
- The 'pkg_info' option was added in version 2.13.
default: ['auto']
choices: ['auto', 'rpm', 'apt', 'portage', 'pkg', 'pacman', 'apk']
choices: ['auto', 'rpm', 'apt', 'portage', 'pkg', 'pacman', 'apk', 'pkg_info']
type: list
elements: str
strategy:
@ -214,6 +215,25 @@ ansible_facts:
],
}
}
# Sample pkg_info
{
"packages": {
"curl": [
{
"name": "curl",
"source": "pkg_info",
"version": "7.79.0"
}
],
"intel-firmware": [
{
"name": "intel-firmware",
"source": "pkg_info",
"version": "20210608v0"
}
],
}
}
'''
import re
@ -436,6 +456,29 @@ class APK(CLIMgr):
return raw_pkg_details
class PKG_INFO(CLIMgr):
CLI = 'pkg_info'
def list_installed(self):
rc, out, err = module.run_command([self._cli, '-a'])
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 = {'name': package, 'version': ''}
details = package.split(maxsplit=1)[0].rsplit('-', maxsplit=1)
try:
return {
'name': details[0],
'version': details[1],
}
except IndexError:
return raw_pkg_details
def main():
# get supported pkg managers

Loading…
Cancel
Save