Merge "Fix idempotence of tweaks::ubuntu_service_override"

This commit is contained in:
Jenkins 2015-12-18 16:11:44 +00:00 committed by Gerrit Code Review
commit 3ec11402cf
4 changed files with 61 additions and 23 deletions

View File

@ -18,9 +18,19 @@ if !(member($roles, 'controller') or member($roles, 'primary-controller')) {
minpoll => '3',
}
include ntp::params
tweaks::ubuntu_service_override { 'ntpd':
package_name => $ntp::params::package_name,
service_name => $ntp::params::service_name,
if $::operatingsystem == 'Ubuntu' {
include ntp::params
# puppetlabs/ntp uses one element array as package_name default value
if is_array($ntp::params::package_name) {
$package_name = $ntp::params::package_name[0]
} else {
$package_name = $ntp::params::package_name
}
tweaks::ubuntu_service_override { 'ntpd':
package_name => $package_name,
service_name => $ntp::params::service_name,
}
}
}

View File

@ -24,8 +24,16 @@ class { 'cluster::ntp_ocf': }
if $::operatingsystem == 'Ubuntu' {
include ntp::params
# puppetlabs/ntp uses one element array as package_name default value
if is_array($ntp::params::package_name) {
$package_name = $ntp::params::package_name[0]
} else {
$package_name = $ntp::params::package_name
}
tweaks::ubuntu_service_override { 'ntpd':
package_name => $ntp::params::package_name,
package_name => $package_name,
service_name => $ntp::params::service_name,
}
}

View File

@ -0,0 +1,19 @@
module Puppet::Parser::Functions
newfunction(:is_pkg_installed,
:type => :rvalue,
:arity => 1,
:doc => <<-'ENDOFDOC'
Returns if given package is installed
ENDOFDOC
) do |args|
pkgname = args[0]
parameters = { :name => pkgname }
res = Puppet::Type.type(:package).new(parameters)
query = res.provider.query
return false if query.nil?
query[:ensure].match(/[-.]|\d+|[^-.\d]+/) != 0
end
end

View File

@ -7,25 +7,26 @@ define tweaks::ubuntu_service_override (
$file_name = "create_${service_name}_override"
$exec_name = "remove_${service_name}_override"
file { $file_name :
ensure => present,
path => $override_file,
content => 'manual',
mode => '0644',
owner => 'root',
group => 'root',
}
if ! is_pkg_installed($package_name) {
file { $file_name :
ensure => present,
path => $override_file,
content => 'manual',
mode => '0644',
owner => 'root',
group => 'root',
}
exec { $exec_name :
path => [ '/sbin', '/bin', '/usr/bin', '/usr/sbin' ],
command => "rm -f ${override_file}",
onlyif => "test -f ${override_file}",
}
exec { $exec_name :
path => [ '/sbin', '/bin', '/usr/bin', '/usr/sbin' ],
command => "rm -f ${override_file}",
onlyif => "test -f ${override_file}",
}
File[$file_name] -> Package <| name == $package_name |> -> Exec[$exec_name]
File[$file_name] -> Package <| title == $package_name |> -> Exec[$exec_name]
File[$file_name] -> Exec[$exec_name]
Exec[$exec_name] -> Service <| name == $service_name |>
Exec[$exec_name] -> Service <| title == $service_name |>
File[$file_name] -> Package <| name == $package_name |> -> Exec[$exec_name]
File[$file_name] -> Package <| title == $package_name |> -> Exec[$exec_name]
Exec[$exec_name] -> Service <| name == $service_name |>
Exec[$exec_name] -> Service <| title == $service_name |>
}
}
}