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[Array[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 # Validate the resource name
43 if $name !~ /^ppa:([a-zA-Z0-9\-_]+)\/([a-zA-z0-9\-_\.]+)$/ {
44 fail("Invalid PPA name: ${name}")
47 if versioncmp($facts['os']['release']['full'], '14.10') >= 0 {
48 $distid = downcase($dist)
49 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2")
50 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2")
52 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2")
53 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2")
56 $dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G')
57 $dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G')
58 $underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G')
59 $underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G')
61 $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list"
63 if versioncmp($facts['os']['release']['full'], '15.10') >= 0 and
64 versioncmp($facts['os']['release']['full'], '21.04') < 0 {
65 $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg"
67 $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg"
70 # This is the location of our main exec script.
71 $cache_path = $facts['puppet_vardir']
72 $script_path = "${cache_path}/add-apt-repository-${dash_filename_no_specialchars}-${release}.sh"
74 if $ensure == 'present' {
76 ensure_packages($package_name)
77 $_require = [File['sources.list.d'], Package[$package_name]]
79 $_require = File['sources.list.d']
82 $_proxy = $apt::_proxy
85 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"]
87 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"]
93 unless $sources_list_d_filename in $facts['apt_sources'] {
94 $script_content = epp('apt/add-apt-repository.sh.epp', {
95 command => ['/usr/bin/add-apt-repository', shell_join($options), $name],
96 sources_list_d_path => $apt::sources_list_d,
97 sources_list_d_filename => $sources_list_d_filename,
101 file { "add-apt-repository-script-${name}":
103 path => $script_path,
104 content => $script_content,
108 exec { "add-apt-repository-${name}":
109 environment => $_proxy_env,
110 command => $script_path,
111 logoutput => 'on_failure',
112 notify => Class['apt::update'],
113 require => $_require,
118 tidy { "remove-apt-repository-script-${name}":
119 path => $script_path,
122 tidy { "remove-apt-repository-${name}":
123 path => "${apt::sources_list_d}/${sources_list_d_filename}",
124 notify => Class['apt::update'],