diff options
Diffstat (limited to 'lib/facter')
-rw-r--r-- | lib/facter/pip_version.rb | 19 | ||||
-rw-r--r-- | lib/facter/python_version.rb | 28 | ||||
-rw-r--r-- | lib/facter/virtualenv_version.rb | 19 |
3 files changed, 66 insertions, 0 deletions
diff --git a/lib/facter/pip_version.rb b/lib/facter/pip_version.rb new file mode 100644 index 0000000..48dd0bf --- /dev/null +++ b/lib/facter/pip_version.rb @@ -0,0 +1,19 @@ +# Make pip version available as a fact +# Works with pip loaded and without, pip installed using pip and package installed +require 'puppet' +pkg = Puppet::Type.type(:package).new(:name => "python-pip") +Facter.add("pip_version") do + has_weight 100 + setcode do + Facter::Util::Resolution.exec('pip --version') + end +end + +Facter.add("pip_version") do + has_weight 50 + setcode do + if pkg.retrieve[pkg.property(:ensure)] != 'purged' + /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] + end + end +end diff --git a/lib/facter/python_version.rb b/lib/facter/python_version.rb new file mode 100644 index 0000000..a2bdb26 --- /dev/null +++ b/lib/facter/python_version.rb @@ -0,0 +1,28 @@ +# Make python versions available as facts +# In lists default python and system python versions +require 'puppet' +pkg = Puppet::Type.type(:package).new(:name => "python") + +Facter.add("system_python_version") do + setcode do + if pkg.retrieve[pkg.property(:ensure)] != 'purged' + /^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] + end + end +end + +Facter.add("python_version") do + has_weight 100 + setcode do + /^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V'))[1] + end +end + +Facter.add("python_version") do + has_weight 50 + setcode do + if pkg.retrieve[pkg.property(:ensure)] != 'purged' + /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] + end + end +end diff --git a/lib/facter/virtualenv_version.rb b/lib/facter/virtualenv_version.rb new file mode 100644 index 0000000..c923b09 --- /dev/null +++ b/lib/facter/virtualenv_version.rb @@ -0,0 +1,19 @@ +# Make virtualenv version available as a fact +# Works with virualenv loaded and without, pip installed and package installed +require 'puppet' +pkg = Puppet::Type.type(:package).new(:name => "virtualenv") +Facter.add("virtualenv_version") do + has_weight 100 + setcode do + Facter::Util::Resolution.exec('virtualenv --version') + end +end + +Facter.add("virtualenv_version") do + has_weight 50 + setcode do + if pkg.retrieve[pkg.property(:ensure)] != 'purged' + /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] + end + end +end |