Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

# Collect facts related to the system package manager 

# 

# This file is part of Ansible 

# 

# Ansible is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# Ansible is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with Ansible. If not, see <http://www.gnu.org/licenses/>. 

 

from __future__ import (absolute_import, division, print_function) 

__metaclass__ = type 

 

import os 

 

from ansible.module_utils.facts.collector import BaseFactCollector 

 

# A list of dicts. If there is a platform with more than one 

# package manager, put the preferred one last. If there is an 

# ansible module, use that as the value for the 'name' key. 

PKG_MGRS = [{'path': '/usr/bin/yum', 'name': 'yum'}, 

{'path': '/usr/bin/dnf', 'name': 'dnf'}, 

{'path': '/usr/bin/apt-get', 'name': 'apt'}, 

{'path': '/usr/bin/zypper', 'name': 'zypper'}, 

{'path': '/usr/sbin/urpmi', 'name': 'urpmi'}, 

{'path': '/usr/bin/pacman', 'name': 'pacman'}, 

{'path': '/bin/opkg', 'name': 'opkg'}, 

{'path': '/usr/pkg/bin/pkgin', 'name': 'pkgin'}, 

{'path': '/opt/local/bin/pkgin', 'name': 'pkgin'}, 

{'path': '/opt/tools/bin/pkgin', 'name': 'pkgin'}, 

{'path': '/opt/local/bin/port', 'name': 'macports'}, 

{'path': '/usr/local/bin/brew', 'name': 'homebrew'}, 

{'path': '/sbin/apk', 'name': 'apk'}, 

{'path': '/usr/sbin/pkg', 'name': 'pkgng'}, 

{'path': '/usr/sbin/swlist', 'name': 'HP-UX'}, 

{'path': '/usr/bin/emerge', 'name': 'portage'}, 

{'path': '/usr/sbin/pkgadd', 'name': 'svr4pkg'}, 

{'path': '/usr/bin/pkg', 'name': 'pkg5'}, 

{'path': '/usr/bin/xbps-install', 'name': 'xbps'}, 

{'path': '/usr/local/sbin/pkg', 'name': 'pkgng'}, 

{'path': '/usr/bin/swupd', 'name': 'swupd'}, 

{'path': '/usr/sbin/sorcery', 'name': 'sorcery'}, 

{'path': '/usr/bin/rpm-ostree', 'name': 'atomic_container'}, 

] 

 

 

class OpenBSDPkgMgrFactCollector(BaseFactCollector): 

name = 'pkg_mgr' 

_fact_ids = set() 

_platform = 'OpenBSD' 

 

def collect(self, module=None, collected_facts=None): 

facts_dict = {} 

 

facts_dict['pkg_mgr'] = 'openbsd_pkg' 

return facts_dict 

 

 

# the fact ends up being 'pkg_mgr' so stick with that naming/spelling 

class PkgMgrFactCollector(BaseFactCollector): 

name = 'pkg_mgr' 

_fact_ids = set() 

_platform = 'Generic' 

 

def collect(self, module=None, collected_facts=None): 

facts_dict = {} 

collected_facts = collected_facts or {} 

 

pkg_mgr_name = 'unknown' 

for pkg in PKG_MGRS: 

if os.path.exists(pkg['path']): 

pkg_mgr_name = pkg['name'] 

 

facts_dict['pkg_mgr'] = pkg_mgr_name 

return facts_dict