Skip to content

Commit

Permalink
prevent Facter error when packages not installed
Browse files Browse the repository at this point in the history
on RHEL systems, `pkg.retrieve[pkg.property(:ensure)]` returns `:absent`
when a package is not installed; this can generate an unsightly error
when running these facts on a RHEL system where the necessary OS
packages are not installed:

    [root@gepeto ~]# facter -p osfamily
    RedHat
    [root@gepeto ~]# facter -p lsbmajdistrelease
    5
    [root@gepeto ~]# grep version /etc/puppet/modules/python/Modulefile
    version      '1.6.3'
    [root@gepeto ~]# facter -p virtualenv_version pip_version
    Could not retrieve virtualenv_version: can't convert Symbol into String
    Could not retrieve pip_version: undefined method `[]' for nil:NilClass
    Could not retrieve pip_version: can't convert Symbol into String
    pip_version =>
    virtualenv_version =>

Fixes #50
  • Loading branch information
hakamadare committed Feb 26, 2014
1 parent 0747976 commit 6b49e5a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/facter/pip_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Facter.add("pip_version") do
has_weight 50
setcode do
if pkg.retrieve[pkg.property(:ensure)] != 'purged'
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/facter/python_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Facter.add("system_python_version") do
setcode do
if pkg.retrieve[pkg.property(:ensure)] != 'purged'
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
/^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
end
end
Expand All @@ -21,7 +21,7 @@
Facter.add("python_version") do
has_weight 50
setcode do
if pkg.retrieve[pkg.property(:ensure)] != 'purged'
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/virtualenv_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Facter.add("virtualenv_version") do
has_weight 50
setcode do
if pkg.retrieve[pkg.property(:ensure)] != 'purged'
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
end
end
Expand Down

0 comments on commit 6b49e5a

Please sign in to comment.