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 # Optional if lsb-release is installed (unless you're using a different release than indicated by lsb-release, e.g., Linux Mint).
14 # Specifies the operating system of your node. Valid options: a string containing a valid LSB distribution codename.
17 # Names the package that provides the `apt-add-repository` command. Default: 'software-properties-common'.
19 # @param package_manage
20 # Specifies whether Puppet should manage the package that provides `apt-add-repository`.
23 String $ensure = 'present',
24 Optional[String] $options = $::apt::ppa_options,
25 Optional[String] $release = $facts['lsbdistcodename'],
26 Optional[String] $package_name = $::apt::ppa_package,
27 Boolean $package_manage = false,
30 fail(translate('lsbdistcodename fact not available: release parameter required'))
33 if $facts['lsbdistid'] == 'Debian' {
34 fail(translate('apt::ppa is not currently supported on Debian.'))
37 if versioncmp($facts['lsbdistrelease'], '14.10') >= 0 {
38 $distid = downcase($facts['lsbdistid'])
39 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2")
40 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2")
42 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2")
43 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2")
46 $dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G')
47 $dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G')
48 $underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G')
49 $underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G')
51 $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list"
53 if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 {
54 $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg"
56 $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg"
59 if $ensure == 'present' {
61 ensure_packages($package_name)
62 $_require = [File['sources.list.d'], Package[$package_name]]
64 $_require = File['sources.list.d']
67 $_proxy = $::apt::_proxy
70 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"]
72 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"]
78 exec { "add-apt-repository-${name}":
79 environment => $_proxy_env,
80 command => "/usr/bin/add-apt-repository ${options} ${name} || (rm ${::apt::sources_list_d}/${sources_list_d_filename} && false)",
81 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}",
83 logoutput => 'on_failure',
84 notify => Class['apt::update'],
88 file { "${::apt::sources_list_d}/${sources_list_d_filename}":
90 require => Exec["add-apt-repository-${name}"],
94 file { "${::apt::sources_list_d}/${sources_list_d_filename}":
96 notify => Class['apt::update'],