1 # @summary Manages PPA repositories using `add-apt-repository`. Not supported on Debian.
3 # @example Example declaration of an Apt PPA
4 # apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': }
7 # Specifies whether the PPA should exist. Valid options: 'present' and 'absent'.
10 # Supplies options to be passed to the `add-apt-repository` command. Default: '-y'.
13 # Specifies the operating system of your node. Valid options: a string containing a valid LSB distribution codename.
14 # Optional if `puppet facts show os.distro.codename` returns your correct distribution release codename.
17 # Specifies the distribution of your node. Valid options: a string containing a valid distribution codename.
18 # Optional if `puppet facts show os.name` returns your correct distribution name.
21 # Names the package that provides the `apt-add-repository` command. Default: 'software-properties-common'.
23 # @param package_manage
24 # Specifies whether Puppet should manage the package that provides `apt-add-repository`.
27 String $ensure = 'present',
28 Optional[String] $options = $::apt::ppa_options,
29 Optional[String] $release = fact('os.distro.codename'),
30 Optional[String] $dist = $facts['os']['name'],
31 Optional[String] $package_name = $::apt::ppa_package,
32 Boolean $package_manage = false,
35 fail('os.distro.codename fact not available: release parameter required')
38 if $dist == 'Debian' {
39 fail('apt::ppa is not currently supported on Debian.')
42 if versioncmp($facts['os']['release']['full'], '14.10') >= 0 {
43 $distid = downcase($dist)
44 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2")
45 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2")
47 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2")
48 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2")
51 $dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G')
52 $dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G')
53 $underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G')
54 $underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G')
56 $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list"
58 if versioncmp($facts['os']['release']['full'], '15.10') >= 0 and
59 versioncmp($facts['os']['release']['full'], '21.04') < 0 {
60 $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg"
62 $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg"
65 if $ensure == 'present' {
67 ensure_packages($package_name)
68 $_require = [File['sources.list.d'], Package[$package_name]]
70 $_require = File['sources.list.d']
73 $_proxy = $::apt::_proxy
76 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"]
78 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"]
84 exec { "add-apt-repository-${name}":
85 environment => $_proxy_env,
86 command => "/usr/bin/add-apt-repository ${options} ${name} || (rm ${::apt::sources_list_d}/${sources_list_d_filename} && false)",
87 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}",
89 logoutput => 'on_failure',
90 notify => Class['apt::update'],
94 file { "${::apt::sources_list_d}/${sources_list_d_filename}":
96 require => Exec["add-apt-repository-${name}"],
100 file { "${::apt::sources_list_d}/${sources_list_d_filename}":
102 notify => Class['apt::update'],