Mercurial > repos > other > Puppet
comparison modules/apt/manifests/ppa.pp @ 386:3fce34f642f1
Add a PHP module to handle platform differences
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 03 Jan 2022 17:09:39 +0000 |
parents | |
children | adf6fe9bbc17 |
comparison
equal
deleted
inserted
replaced
385:d9009f54eb23 | 386:3fce34f642f1 |
---|---|
1 # @summary Manages PPA repositories using `add-apt-repository`. Not supported on Debian. | |
2 # | |
3 # @example Example declaration of an Apt PPA | |
4 # apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': } | |
5 # | |
6 # @param ensure | |
7 # Specifies whether the PPA should exist. Valid options: 'present' and 'absent'. | |
8 # | |
9 # @param options | |
10 # Supplies options to be passed to the `add-apt-repository` command. Default: '-y'. | |
11 # | |
12 # @param release | |
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. | |
15 # | |
16 # @param dist | |
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. | |
19 # | |
20 # @param package_name | |
21 # Names the package that provides the `apt-add-repository` command. Default: 'software-properties-common'. | |
22 # | |
23 # @param package_manage | |
24 # Specifies whether Puppet should manage the package that provides `apt-add-repository`. | |
25 # | |
26 define apt::ppa( | |
27 String $ensure = 'present', | |
28 Optional[String] $options = $::apt::ppa_options, | |
29 Optional[String] $release = $facts['os']['distro']['codename'], | |
30 Optional[String] $dist = $facts['os']['name'], | |
31 Optional[String] $package_name = $::apt::ppa_package, | |
32 Boolean $package_manage = false, | |
33 ) { | |
34 unless $release { | |
35 fail('os.distro.codename fact not available: release parameter required') | |
36 } | |
37 | |
38 if $dist == 'Debian' { | |
39 fail('apt::ppa is not currently supported on Debian.') | |
40 } | |
41 | |
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") | |
46 } else { | |
47 $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2") | |
48 $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2") | |
49 } | |
50 | |
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') | |
55 | |
56 $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list" | |
57 | |
58 if versioncmp($facts['os']['release']['full'], '15.10') >= 0 { | |
59 $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg" | |
60 } else { | |
61 $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg" | |
62 } | |
63 | |
64 if $ensure == 'present' { | |
65 if $package_manage { | |
66 ensure_packages($package_name) | |
67 $_require = [File['sources.list.d'], Package[$package_name]] | |
68 } else { | |
69 $_require = File['sources.list.d'] | |
70 } | |
71 | |
72 $_proxy = $::apt::_proxy | |
73 if $_proxy['host'] { | |
74 if $_proxy['https'] { | |
75 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"] | |
76 } else { | |
77 $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"] | |
78 } | |
79 } else { | |
80 $_proxy_env = [] | |
81 } | |
82 | |
83 exec { "add-apt-repository-${name}": | |
84 environment => $_proxy_env, | |
85 command => "/usr/bin/add-apt-repository ${options} ${name} || (rm ${::apt::sources_list_d}/${sources_list_d_filename} && false)", | |
86 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}", | |
87 user => 'root', | |
88 logoutput => 'on_failure', | |
89 notify => Class['apt::update'], | |
90 require => $_require, | |
91 } | |
92 | |
93 file { "${::apt::sources_list_d}/${sources_list_d_filename}": | |
94 ensure => file, | |
95 require => Exec["add-apt-repository-${name}"], | |
96 } | |
97 } | |
98 else { | |
99 file { "${::apt::sources_list_d}/${sources_list_d_filename}": | |
100 ensure => 'absent', | |
101 notify => Class['apt::update'], | |
102 } | |
103 } | |
104 } |