X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fppa.pp;h=f3613a0b56523fd62b86a49a557271fa8773015a;hb=58265f32854aaaa03d1abb83c1511563a2879e0b;hp=788262f09f4d48c20f14127f008ea5f62284d0f1;hpb=e75e603d339ee2741c73967da19493298530629a;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/ppa.pp b/manifests/ppa.pp index 788262f..f3613a0 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -1,76 +1,126 @@ -# ppa.pp -define apt::ppa( - $ensure = 'present', - $release = $::lsbdistcodename, - $options = $apt::params::ppa_options, +# @summary Manages PPA repositories using `add-apt-repository`. Not supported on Debian. +# +# @example Example declaration of an Apt PPA +# apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': } +# +# @param ensure +# 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 +# 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 +# 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'. +# +# @param package_manage +# Specifies whether Puppet should manage the package that provides `apt-add-repository`. +# +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, ) { - $sources_list_d = $apt::params::sources_list_d + unless $release { + fail('os.distro.codename fact not available: release parameter required') + } - if ! $release { - fail('lsbdistcodename fact not available: release parameter required') + if $dist == 'Debian' { + fail('apt::ppa is not currently supported on Debian.') } - if $::operatingsystem != 'Ubuntu' { - fail('apt::ppa is currently supported on Ubuntu only.') + # Validate the resource name + if $name !~ /^ppa:([a-zA-Z0-9\-_]+)\/([a-zA-z0-9\-_]+)$/ { + fail("Invalid PPA name: ${name}") } - $filename_without_slashes = regsubst($name, '/', '-', 'G') - $filename_without_dots = regsubst($filename_without_slashes, '\.', '_', 'G') - $filename_without_ppa = regsubst($filename_without_dots, '^ppa:', '', 'G') - $sources_list_d_filename = "${filename_without_ppa}-${release}.list" + 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") + } else { + $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2") + $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2") + } - if $ensure == 'present' { - $package = $::lsbdistrelease ? { - /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties', - default => 'software-properties-common', - } + $dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G') + $dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G') + $underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G') + $underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G') - if ! defined(Package[$package]) { - package { $package: } - } + $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list" - if defined(Class[apt]) { - $proxy_host = $apt::proxy_host - $proxy_port = $apt::proxy_port - case $proxy_host { - false, '', undef: { - $proxy_env = [] - } - default: { - $proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"] - } - } + 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) + $_require = [File['sources.list.d'], Package[$package_name]] } else { - $proxy_env = [] + $_require = File['sources.list.d'] } - exec { "add-apt-repository-${name}": - environment => $proxy_env, - command => "/usr/bin/add-apt-repository ${options} ${name}", - unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}", - user => 'root', - logoutput => 'on_failure', - notify => Exec['apt_update'], - require => [ - File['sources.list.d'], - Package[$package], - ], + + $_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']}"] + } else { + $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"] + } + } else { + $_proxy_env = [] } - file { "${sources_list_d}/${sources_list_d_filename}": - ensure => file, - require => Exec["add-apt-repository-${name}"], + 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', + } + + exec { "add-apt-repository-${name}": + environment => $_proxy_env, + command => $script_path, + logoutput => 'on_failure', + notify => Class['apt::update'], + require => $_require, + } } } else { - - file { "${sources_list_d}/${sources_list_d_filename}": - ensure => 'absent', - notify => Exec['apt_update'], + tidy { "remove-apt-repository-script-${name}": + path => $script_path, } - } - # Need anchor to provide containment for dependencies. - anchor { "apt::ppa::${name}": - require => Class['apt::update'], + tidy { "remove-apt-repository-${name}": + path => "${::apt::sources_list_d}/${sources_list_d_filename}", + notify => Class['apt::update'], + } } }