X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fforce.pp;h=152bb67354db6fa8960a20a942329f0cf5d7b147;hb=60e50a9b65dec94fe20734404295e28d9e434a83;hp=0089bbd75393d02044e62427a7470a0528405b31;hpb=42af4cdc74f1b9fbe53da99ef77126274c2124c2;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/force.pp b/manifests/force.pp index 0089bbd..152bb67 100644 --- a/manifests/force.pp +++ b/manifests/force.pp @@ -2,20 +2,41 @@ # force a package from a specific release define apt::force( - $release = 'testing', - $version = false + $release = false, + $version = false, + $timeout = 300 ) { + $provider = $apt::params::provider + $version_string = $version ? { false => undef, default => "=${version}", } - $install_check = $version ? { - false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'", - default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'", + $release_string = $release ? { + false => undef, + default => "-t ${release}", } - exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}": - unless => $install_check, + + if $version == false { + if $release == false { + $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'" + } else { + # If installed version and candidate version differ, this check returns 1 (false). + $install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" + } + } else { + if $release == false { + $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'" + } else { + $install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'" + } + } + + exec { "${provider} -y ${release_string} install ${name}${version_string}": + unless => $install_check, + logoutput => 'on_failure', + timeout => $timeout, } }