Class: Inspec::Resources::Rpm

Inherits:
PkgManagement show all
Defined in:
lib/resources/package.rb

Overview

RHEL family

Instance Attribute Summary

Attributes inherited from PkgManagement

#inspec

Instance Method Summary collapse

Methods inherited from PkgManagement

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::PkgManagement

Instance Method Details

#info(package_name) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/resources/package.rb', line 107

def info(package_name)
  cmd = inspec.command("rpm -qia #{package_name}")
  # CentOS does not return an error code if the package is not installed,
  # therefore we need to check for emptyness
  return nil if cmd.exit_status.to_i != 0 || cmd.stdout.chomp.empty?
  params = SimpleConfig.new(
    cmd.stdout.chomp,
    assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: false,
  ).params
  # On some (all?) systems, the linebreak before the vendor line is missing
  if params['Version'] =~ /\s*Vendor:/
    v = params['Version'].split(' ')[0]
  else
    v = params['Version']
  end
  # On some (all?) systems, the linebreak before the build line is missing
  if params['Release'] =~ /\s*Build Date:/
    r = params['Release'].split(' ')[0]
  else
    r = params['Release']
  end
  {
    name: params['Name'],
    installed: true,
    version: "#{v}-#{r}",
    type: 'rpm',
  }
end