X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fppa.pp;h=2a5b4a868de955037e5e42c1c842e1fffa387662;hb=refs%2Fheads%2Fpdksync_%28MAINT%29_Pin_puppetlabs-puppet_agent;hp=ba05485c31c2ed5792cab8f0ae0a5fb85660627b;hpb=018b71d33d4a1e971ceb8977682f0324de0fc997;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/ppa.pp b/manifests/ppa.pp index ba05485..2a5b4a8 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -4,18 +4,18 @@ # apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': } # # @param ensure -# Specifies whether the PPA should exist. Valid options: 'present' and 'absent'. +# Specifies whether the PPA should exist. Valid options: 'present' and 'absent'. # # @param options # Supplies options to be passed to the `add-apt-repository` command. Default: '-y'. # # @param release -# Optional if lsb-release is installed (unless you're using a different release than indicated by lsb-release, e.g., Linux Mint). # Specifies the operating system of your node. Valid options: a string containing a valid LSB distribution codename. +# Optional if `puppet facts show os.distro.codename` returns your correct distribution release codename. # # @param dist -# Optional if lsb-release is installed (unless you're using a different release than indicated by lsb-release, e.g., Linux Mint). # Specifies the distribution of your node. Valid options: a string containing a valid distribution codename. +# Optional if `puppet facts show os.name` returns your correct distribution name. # # @param package_name # Names the package that provides the `apt-add-repository` command. Default: 'software-properties-common'. @@ -23,23 +23,28 @@ # @param package_manage # Specifies whether Puppet should manage the package that provides `apt-add-repository`. # -define apt::ppa( - String $ensure = 'present', - Optional[String] $options = $::apt::ppa_options, - Optional[String] $release = $facts['lsbdistcodename'], - Optional[String] $dist = $facts['lsbdistid'], - Optional[String] $package_name = $::apt::ppa_package, - Boolean $package_manage = false, +define apt::ppa ( + String $ensure = 'present', + Optional[Array[String]] $options = $apt::ppa_options, + Optional[String] $release = fact('os.distro.codename'), + Optional[String] $dist = $facts['os']['name'], + Optional[String] $package_name = $apt::ppa_package, + Boolean $package_manage = false, ) { unless $release { - fail(translate('lsbdistcodename fact not available: release parameter required')) + fail('os.distro.codename fact not available: release parameter required') } if $dist == 'Debian' { - fail(translate('apt::ppa is not currently supported on Debian.')) + fail('apt::ppa is not currently supported on Debian.') } - if versioncmp($facts['lsbdistrelease'], '14.10') >= 0 { + # Validate the resource name + if $name !~ /^ppa:([a-zA-Z0-9\-_.]+)\/([a-zA-z0-9\-_\.]+)$/ { + fail("Invalid PPA name: ${name}") + } + + if versioncmp($facts['os']['release']['full'], '14.10') >= 0 { $distid = downcase($dist) $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2") $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2") @@ -55,12 +60,17 @@ define apt::ppa( $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list" - if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 { + if versioncmp($facts['os']['release']['full'], '15.10') >= 0 and + versioncmp($facts['os']['release']['full'], '21.04') < 0 { $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg" } else { $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg" } + # This is the location of our main exec script. + $cache_path = $facts['puppet_vardir'] + $script_path = "${cache_path}/add-apt-repository-${dash_filename_no_specialchars}-${release}.sh" + if $ensure == 'present' { if $package_manage { ensure_packages($package_name) @@ -69,7 +79,7 @@ define apt::ppa( $_require = File['sources.list.d'] } - $_proxy = $::apt::_proxy + $_proxy = $apt::_proxy if $_proxy['host'] { if $_proxy['https'] { $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"] @@ -80,24 +90,40 @@ define apt::ppa( $_proxy_env = [] } - exec { "add-apt-repository-${name}": - environment => $_proxy_env, - command => "/usr/bin/add-apt-repository ${options} ${name} || (rm ${::apt::sources_list_d}/${sources_list_d_filename} && false)", - unless => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename} && /usr/bin/test -f ${::apt::trusted_gpg_d}/${trusted_gpg_d_filename}", - user => 'root', - logoutput => 'on_failure', - notify => Class['apt::update'], - require => $_require, - } + unless $sources_list_d_filename in $facts['apt_sources'] { + $script_content = epp('apt/add-apt-repository.sh.epp', { + command => ['/usr/bin/add-apt-repository', shell_join($options), $name], + sources_list_d_path => $apt::sources_list_d, + sources_list_d_filename => $sources_list_d_filename, + } + ) + + file { "add-apt-repository-script-${name}": + ensure => 'file', + path => $script_path, + content => $script_content, + mode => '0755', + } - file { "${::apt::sources_list_d}/${sources_list_d_filename}": - ensure => file, - require => Exec["add-apt-repository-${name}"], + exec { "add-apt-repository-${name}": + environment => $_proxy_env, + command => $script_path, + logoutput => 'on_failure', + notify => Class['apt::update'], + require => $_require, + before => File["${apt::sources_list_d}/${sources_list_d_filename}"], + } } + + file { "${apt::sources_list_d}/${sources_list_d_filename}": } } else { - file { "${::apt::sources_list_d}/${sources_list_d_filename}": - ensure => 'absent', + tidy { "remove-apt-repository-script-${name}": + path => $script_path, + } + + tidy { "remove-apt-repository-${name}": + path => "${apt::sources_list_d}/${sources_list_d_filename}", notify => Class['apt::update'], } }