Beispiel #1
0
    def chroot_conf():
        """Obtain information about the distribution, version, and architecture of the target.

        Returns:
            Chroot info in the form of distribution-version-architecture.
        """
        (distribution, version, codename) = distro.linux_distribution(full_distribution_name=False)
        base = CoprModule.get_base()
        return "{0}-{1}-{2}".format(distribution, version, base.conf.arch)
Beispiel #2
0
    def __init__(self, module):

        self.module = module

        self.state = module.params.get("state")
        self.package_name = module.params.get("package_name")

        (self.distribution, self.version, self.codename) = distro.linux_distribution(
            full_distribution_name=False
        )
Beispiel #3
0
    def __init__(self, module):
        """
          Initialize all needed Variables
        """
        self.module = module
        self.package_version = module.params.get("package_version")

        (self.distribution, self.version,
         self.codename) = distro.linux_distribution(
             full_distribution_name=False)
    def run(self):

        result = dict(changed=False, failed=True, msg="initial")

        (distribution, version,
         codename) = distro.linux_distribution(full_distribution_name=False)

        self.module.log(msg="distribution       : '{0}'".format(distribution))

        if (distribution.lower() in ["centos", "oracle", "redhat", "fedora"]):
            """
              redhat based
            """
            package_mgr = self.module.get_bin_path('yum', False)

            if (not package_mgr):
                package_mgr = self.module.get_bin_path('dnf', True)

            if (not package_mgr):
                return True, "", "no valid package manager (yum or dnf) found"

            self.module.log(msg="  '{0}'".format(package_mgr))

            rc, out, err = self.module.run_command([
                package_mgr, "list", "installed", "--cacheonly",
                "*{0}*".format(self.package_name)
            ],
                                                   check_rc=False)

            pattern = re.compile(
                r".*{0}.*(?P<version>[0-9]+\.[0-9]+)\..*@(?P<repo>.*)".format(
                    self.package_name))

            version = re.search(pattern, out)

            if (version):
                version_string = version.group('version')
                version_string_compressed = version_string.replace('.', '')

                result = dict(failed=False,
                              version=version_string,
                              version_compressed=version_string_compressed)
            else:
                result = dict(
                    failed=False,
                    msg="package {0} is not installed".format(
                        self.package_name),
                )

        elif (distribution.lower() in ["debian", "ubuntu"]):
            """
              debain based
            """
            import apt

            cache = apt.cache.Cache()
            cache.update()
            cache.open()

            try:
                pkg = cache[self.package_name]

                # debian:10 / buster:
                #  [php-fpm=2:7.3+69]
                # ubuntu:20.04 / focal
                #  [php-fpm=2:7.4+75]
                if (pkg):
                    pkg_version = pkg.versions[0]
                    version = pkg_version.version
                    pattern = re.compile(r'^\d:(?P<version>\d.+)\+.*')
                    version = re.search(pattern, version)

                    version_string = version.group('version')
                    version_string_compressed = version_string.replace('.', '')

                result = dict(failed=False,
                              version=version_string,
                              version_compressed=version_string_compressed)
            except KeyError as error:
                self.module.log(msg="error         : {0}".format(error))

                result = dict(
                    failed=False,
                    msg="package {0} is not installed".format(
                        self.package_name),
                )

        else:
            """
              all others
            """
            result = dict(failed=False,
                          msg="unknown distribution: {0}".format(distribution),
                          version="")

        return result
Beispiel #5
0
 def test_linux_distribution(self):
     linux_dist = distro.linux_distribution()
     assert isinstance(linux_dist, tuple), \
         'linux_distrution() returned %s (%s) which is not a tuple' % (linux_dist, type(linux_dist))
 def version(self):
     result = distro.linux_distribution()[1]
     return result
Beispiel #7
0
    '/etc/os-release',
    '/etc/coreos/update.conf',
    '/etc/flatcar/update.conf',
    '/usr/lib/os-release',
]

fcont = {}

for f in filelist:
    if os.path.exists(f):
        s = os.path.getsize(f)
        if s > 0 and s < 10000:
            with open(f) as fh:
                fcont[f] = fh.read()

dist = distro.linux_distribution(full_distribution_name=False)

facts = [
    'distribution', 'distribution_version', 'distribution_release',
    'distribution_major_version', 'os_family'
]

try:
    b_ansible_out = subprocess.check_output(
        ['ansible', 'localhost', '-m', 'setup'])
except subprocess.CalledProcessError as e:
    print("ERROR: ansible run failed, output was: \n")
    print(e.output)
    sys.exit(e.returncode)

ansible_out = to_text(b_ansible_out)