Skip to content

Commit

Permalink
Merge pull request #6 from jpoittevin/master_versionlock_concat
Browse files Browse the repository at this point in the history
Manage yum::versionlock with concat
  • Loading branch information
jyaworski authored Aug 23, 2016
2 parents 15133a7 + 4a0889e commit c25fbdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
8 changes: 7 additions & 1 deletion manifests/plugin/versionlock.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
# include yum::plugin::versionlock
#
class yum::plugin::versionlock (
$ensure = present
$ensure = present,
$path = '/etc/yum/pluginconf.d/versionlock.list'
) {
yum::plugin { 'versionlock':
ensure => $ensure,
}
concat { $path:
mode => '0644',
owner => 'root',
group => 'root',
}
}
36 changes: 15 additions & 21 deletions manifests/versionlock.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# Parameters:
# [*ensure*] - specifies if versionlock should be present, absent or exclude
# [*path*] - configuration of Yum plugin versionlock
#
# Actions:
#
Expand All @@ -18,37 +17,32 @@
#
define yum::versionlock (
$ensure = present,
$path = '/etc/yum/pluginconf.d/versionlock.list'
) {
require ::yum::plugin::versionlock
include ::yum::plugin::versionlock

if ($name =~ /^[0-9]+:.+\*$/) {
$_name = $name
$line = $name
} elsif ($name =~ /^[0-9]+:.+-.+-.+\./) {
$_name= "${name}*"
$line= "${name}*"
} else {
fail('Package name must be formated as \'EPOCH:NAME-VERSION-RELEASE.ARCH\'')
}

case $ensure {
'present', 'absent', 'exclude': {
if ($ensure == present) or ($ensure == absent) {
file_line { "versionlock.list-${name}":
ensure => $ensure,
line => $_name,
path => $path,
}
}
$line_prefix = $ensure ? {
'exclude' => '!',
default => '',
}

if ($ensure == exclude) or ($ensure == absent) {
file_line { "versionlock.list-!${name}":
ensure => $ensure,
line => "!${_name}",
path => $path,
}
case $ensure {
'present','exclude': {
concat::fragment { "yum-versionlock-${name}":
content => "${line_prefix}${line}\n",
target => $yum::plugin::versionlock::path,
}
}

'absent':{
# fragment will be removed
}
default: {
fail("Invalid ensure state: ${ensure}")
}
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.2.0 < 5.0.0"
},
{
"name": "puppetlabs/concat",
"version_requirement": ">= 1.1.1"
}
],
"tags": [
Expand Down

0 comments on commit c25fbdf

Please sign in to comment.