Implement SemVerRange type support for the yum provider. Sample manifest with a range passed for a package:
|
package { 'puppet-agent': |
# this will be parsed as: >= 6.0.0 < 6.1.0 |
ensure => SemVerRange('~> 6.0') |
} |
|
package { 'puppet-agent': |
ensure => SemVerRange('>= 6.5') |
} |
|
package { 'puppet-agent': |
ensure => SemVerRange('< 6.4') |
} |
|
package { 'puppet-agent': |
# this is a valid range which we can support |
ensure => SemVerRange('~> 6.0 || ~> 6.11') |
}
|
The yum provider does not support a version range passed in the install command, so we have to:
- find out the available versions for a specific package (usually with yum list --showduplicates)
- install the most recent package which respects the range.
We should also make sure we don't take additional actions if the range is already satisfied (i.e. puppet apply with a SemVerRange should be idempotent) Sample code on how the ensure property can be treated inside the provider:
|
if @resource.should(:ensure).is_a?(SemanticPuppet::VersionRange) |
# these should be sorted in descending order |
_, *versions = `yum list -d 0 -e 1 --showduplicates #{@resource.name} | awk '{print $2}'`.split |
range = @resource.should(:ensure) |
|
available.versions.any? { |version| range.include?(version.to_stable) } |
end
|
Example yum install with a specific version (package name and version are joined by a dash):
yum install puppet-agent-6.0.4-1.el7 |
|