Skip to content

Commit a240721

Browse files
authored
Merge pull request #713 from StatensPensjonskasse/apt-key-to-keyring
Use keyring for apt repository; update dependency versions
2 parents b4f0d17 + 51c4973 commit a240721

File tree

7 files changed

+195
-85
lines changed

7 files changed

+195
-85
lines changed

REFERENCE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ class {'mongodb::globals':
109109
-> class {'mongodb::server': }
110110
```
111111

112+
##### Use a custom MongoDB apt repository.
113+
114+
```puppet
115+
116+
class {'mongodb::globals':
117+
manage_package_repo => true,
118+
repo_location => 'https://example.com/repo',
119+
keyring_location => 'https://example.com/keyring.asc'
120+
}
121+
-> class {'mongodb::client': }
122+
-> class {'mongodb::server': }
123+
```
124+
112125
##### To disable managing of repository, but still enable managing packages.
113126

114127
```puppet
@@ -145,6 +158,7 @@ The following parameters are available in the `mongodb::globals` class:
145158
* [`proxy_username`](#-mongodb--globals--proxy_username)
146159
* [`proxy_password`](#-mongodb--globals--proxy_password)
147160
* [`repo_location`](#-mongodb--globals--repo_location)
161+
* [`keyring_location`](#-mongodb--globals--keyring_location)
148162
* [`use_enterprise_repo`](#-mongodb--globals--use_enterprise_repo)
149163
* [`pidfilepath`](#-mongodb--globals--pidfilepath)
150164
* [`pidfilemode`](#-mongodb--globals--pidfilemode)
@@ -324,6 +338,15 @@ If not specified, the module will use the default repository for your OS distro.
324338

325339
Default value: `undef`
326340

341+
##### <a name="-mongodb--globals--keyring_location"></a>`keyring_location`
342+
343+
Data type: `Any`
344+
345+
When `repo_location` is used for an apt repository this setting can be used for the keyring
346+
file to download.
347+
348+
Default value: `undef`
349+
327350
##### <a name="-mongodb--globals--use_enterprise_repo"></a>`use_enterprise_repo`
328351

329352
Data type: `Any`

manifests/globals.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
# -> class {'mongodb::client': }
2020
# -> class {'mongodb::server': }
2121
#
22+
# @example Use a custom MongoDB apt repository.
23+
#
24+
# class {'mongodb::globals':
25+
# manage_package_repo => true,
26+
# repo_location => 'https://example.com/repo',
27+
# keyring_location => 'https://example.com/keyring.asc'
28+
# }
29+
# -> class {'mongodb::client': }
30+
# -> class {'mongodb::server': }
31+
#
2232
# @example To disable managing of repository, but still enable managing packages.
2333
#
2434
# class {'mongodb::globals':
@@ -101,6 +111,10 @@
101111
# This setting can be used to override the default MongoDB repository location.
102112
# If not specified, the module will use the default repository for your OS distro.
103113
#
114+
# @param keyring_location
115+
# When `repo_location` is used for an apt repository this setting can be used for the keyring
116+
# file to download.
117+
#
104118
# @param use_enterprise_repo
105119
# When manage_package_repo is set to true, this setting indicates if it will use the Community Edition
106120
# (false, the default) or the Enterprise one (true).
@@ -139,6 +153,7 @@
139153
$proxy_password = undef,
140154

141155
$repo_location = undef,
156+
$keyring_location = undef,
142157
$use_enterprise_repo = undef,
143158

144159
$pidfilepath = undef,
@@ -158,7 +173,10 @@
158173
version => $repo_version,
159174
use_enterprise_repo => $use_enterprise_repo,
160175
repo_location => $repo_location,
176+
keyring_location => $keyring_location,
161177
proxy => $repo_proxy,
178+
proxy_username => $proxy_username,
179+
proxy_password => $proxy_password,
162180
}
163181
}
164182
}

manifests/repo.pp

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# @param repo_location
1616
# Location of the upstream repository
1717
#
18+
# @param keyring_location
19+
# Location of the upstream keyring
20+
#
1821
# @param proxy
1922
# Proxy hostnam
2023
#
@@ -24,18 +27,15 @@
2427
# @param proxy_password
2528
# Proxy pasword
2629
#
27-
# @param aptkey_options
28-
# Options for debian aptkey
29-
#
3030
class mongodb::repo (
31-
Enum['present', 'absent'] $ensure = 'present',
32-
Optional[String] $version = undef,
33-
Boolean $use_enterprise_repo = false,
34-
Optional[String] $repo_location = undef,
35-
Optional[String] $proxy = undef,
36-
Optional[String] $proxy_username = undef,
37-
Optional[String] $proxy_password = undef,
38-
Optional[String[1]] $aptkey_options = undef,
31+
Enum['present', 'absent'] $ensure = 'present',
32+
Optional[String] $version = undef,
33+
Boolean $use_enterprise_repo = false,
34+
Optional[String[1]] $repo_location = undef,
35+
Optional[String[1]] $keyring_location = undef,
36+
Optional[String[1]] $proxy = undef,
37+
Optional[String[1]] $proxy_username = undef,
38+
Optional[String[1]] $proxy_password = undef,
3939
) {
4040
if $version == undef and $repo_location == undef {
4141
fail('`version` or `repo_location` is required')
@@ -50,36 +50,48 @@
5050
case $facts['os']['family'] {
5151
'RedHat', 'Linux': {
5252
if $repo_location != undef {
53-
$location = $repo_location
53+
$_repo_location = $repo_location
5454
$description = 'MongoDB Custom Repository'
5555
} else {
5656
if $use_enterprise_repo {
57-
$location = "https://repo.mongodb.com/yum/redhat/\$releasever/mongodb-enterprise/${version}/\$basearch/"
57+
$_repo_location = "https://repo.mongodb.com/yum/redhat/\$releasever/mongodb-enterprise/${version}/\$basearch/"
5858
$description = 'MongoDB Enterprise Repository'
5959
} else {
60-
$location = "https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${version}/\$basearch/"
60+
$_repo_location = "https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${version}/\$basearch/"
6161
$description = 'MongoDB Repository'
6262
}
6363
}
6464

65-
contain mongodb::repo::yum
65+
class { 'mongodb::repo::yum':
66+
ensure => $ensure,
67+
repo_location => $_repo_location,
68+
description => $description,
69+
proxy => $proxy,
70+
proxy_username => $proxy_username,
71+
proxy_password => $proxy_password,
72+
}
6673
}
6774

6875
'Suse': {
6976
if $repo_location {
70-
$location = $repo_location
77+
$_repo_location = $repo_location
7178
$description = 'MongoDB Custom Repository'
7279
} else {
73-
$location = "https://repo.mongodb.org/zypper/suse/\$releasever_major/mongodb-org/${version}/\$basearch/"
80+
$_repo_location = "https://repo.mongodb.org/zypper/suse/\$releasever_major/mongodb-org/${version}/\$basearch/"
7481
$description = 'MongoDB Repository'
7582
}
7683

77-
contain mongodb::repo::zypper
84+
class { 'mongodb::repo::zypper':
85+
ensure => $ensure,
86+
repo_location => $_repo_location,
87+
description => $description,
88+
}
7889
}
7990

8091
'Debian': {
8192
if $repo_location != undef {
82-
$location = $repo_location
93+
$_repo_location = $repo_location
94+
$_keyring_location = $keyring_location
8395
} else {
8496
if $use_enterprise_repo == true {
8597
$repo_domain = 'repo.mongodb.com'
@@ -89,31 +101,34 @@
89101
$repo_path = 'mongodb-org'
90102
}
91103

92-
$location = $facts['os']['name'] ? {
104+
$_repo_location = $facts['os']['name'] ? {
93105
'Debian' => "https://${repo_domain}/apt/debian",
94106
'Ubuntu' => "https://${repo_domain}/apt/ubuntu",
95107
default => undef
96108
}
109+
$_keyring_location = "https://www.mongodb.org/static/pgp/server-${version}.asc"
97110
$release = "${facts['os']['distro']['codename']}/${repo_path}/${version}"
98111
$repos = $facts['os']['name'] ? {
99112
'Debian' => 'main',
100113
'Ubuntu' => 'multiverse',
101114
default => undef
102115
}
103-
$key = $version ? {
104-
'5.0' => 'F5679A222C647C87527C2F8CB00A0BD1E2C63C11',
105-
'4.4' => '20691EEC35216C63CAF66CE1656408E390CFB1F5',
106-
default => '20691EEC35216C63CAF66CE1656408E390CFB1F5'
107-
}
108-
$key_server = 'hkp://keyserver.ubuntu.com:80'
116+
$comment = 'MongoDB Repository'
109117
}
110118

111-
contain mongodb::repo::apt
119+
class { 'mongodb::repo::apt':
120+
ensure => $ensure,
121+
repo_location => $_repo_location,
122+
keyring_location => $_keyring_location,
123+
release => $release,
124+
repos => $repos,
125+
comment => $comment,
126+
}
112127
}
113128

114129
default: {
115130
if($ensure == 'present') {
116-
fail("Unsupported managed repository for osfamily: ${facts['os']['family']}, operatingsystem: ${facts['os']['name']}, module ${module_name} currently only supports managing repos for osfamily RedHat, Suse, Debian and Ubuntu")
131+
fail("Unsupported managed repository for osfamily: ${facts['os']['family']}, operatingsystem: ${facts['os']['name']}")
117132
}
118133
}
119134
}

manifests/repo/apt.pp

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,58 @@
1+
# @api private
2+
#
13
# @summary This is a repo class for apt
24
#
3-
# @api private
4-
class mongodb::repo::apt inherits mongodb::repo {
5+
# @param ensure
6+
# present or absent
7+
#
8+
# @param repo_location
9+
# Location of the upstream repository
10+
#
11+
# @param keyring_location
12+
# Location of the upstream keyring
13+
#
14+
# @param version
15+
# The version of the mongodb repo
16+
#
17+
# @param release
18+
# Specifies a distribution of the Apt repository.
19+
#
20+
# @param repos
21+
# Specifies a component of the Apt repository.
22+
#
23+
# @param comment
24+
# Supplies a comment for adding to the Apt source file.
25+
#
26+
class mongodb::repo::apt (
27+
Enum['present', 'absent'] $ensure,
28+
String[1] $repo_location,
29+
String[1] $keyring_location,
30+
Optional[String[1]] $release = undef,
31+
Optional[String[1]] $repos = undef,
32+
Optional[String[1]] $comment = undef,
33+
) {
534
# we try to follow/reproduce the instruction
635
# from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
736

37+
assert_private()
38+
839
include apt
940

10-
if($mongodb::repo::ensure == 'present' or $mongodb::repo::ensure == true) {
11-
apt::source { 'mongodb':
12-
location => $mongodb::repo::location,
13-
release => $mongodb::repo::release,
14-
repos => $mongodb::repo::repos,
15-
key => {
16-
'id' => $mongodb::repo::key,
17-
'server' => $mongodb::repo::key_server,
18-
'options' => $mongodb::repo::aptkey_options,
19-
},
20-
}
41+
$keyring_file = split($keyring_location, '/')[-1]
42+
apt::source { 'mongodb':
43+
ensure => $ensure,
44+
location => $repo_location,
45+
release => $mongodb::repo::release,
46+
repos => $mongodb::repo::repos,
47+
key => {
48+
dir => '/usr/share/keyrings/',
49+
name => "mongodb-${keyring_file}",
50+
source => $keyring_location,
51+
},
52+
comment => $comment,
53+
}
2154

55+
if($ensure == 'present') {
2256
Apt::Source['mongodb'] -> Class['apt::update'] -> Package<| tag == 'mongodb_package' |>
2357
}
24-
else {
25-
apt::source { 'mongodb':
26-
ensure => absent,
27-
}
28-
}
2958
}

manifests/repo/yum.pp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
1+
# @api private
2+
#
13
# @summary This is a repo class for yum
24
#
3-
# @api private
4-
class mongodb::repo::yum inherits mongodb::repo {
5+
# @param ensure
6+
# present or absent
7+
#
8+
# @param repo_location
9+
# Location of the upstream repository
10+
#
11+
# @param description
12+
# A human-readable description of the repository.
13+
#
14+
# @param proxy
15+
# Proxy hostnam
16+
#
17+
# @param proxy_username
18+
# Proxy user name
19+
#
20+
# @param proxy_password
21+
# Proxy pasword
22+
#
23+
class mongodb::repo::yum (
24+
Enum['present', 'absent'] $ensure,
25+
String[1] $repo_location,
26+
String[1] $description,
27+
Optional[String[1]] $proxy = undef,
28+
Optional[String[1]] $proxy_username = undef,
29+
Optional[String[1]] $proxy_password = undef,
30+
) {
531
# We try to follow/reproduce the instruction
6-
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/
32+
# https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-red-hat/
733

8-
if $mongodb::repo::ensure == 'present' or $mongodb::repo::ensure == true {
9-
yumrepo { 'mongodb':
10-
descr => $mongodb::repo::description,
11-
baseurl => $mongodb::repo::location,
12-
gpgcheck => '0',
13-
enabled => '1',
14-
proxy => $mongodb::repo::proxy,
15-
proxy_username => $mongodb::repo::proxy_username,
16-
proxy_password => $mongodb::repo::proxy_password,
17-
}
18-
Yumrepo['mongodb'] -> Package<| tag == 'mongodb_package' |>
34+
yumrepo { 'mongodb':
35+
ensure => $ensure,
36+
descr => $description,
37+
baseurl => $repo_location,
38+
gpgcheck => '0',
39+
enabled => '1',
40+
proxy => $proxy,
41+
proxy_username => $proxy_username,
42+
proxy_password => $proxy_password,
1943
}
20-
else {
21-
yumrepo { 'mongodb':
22-
ensure => absent,
23-
}
44+
if $ensure == 'present' {
45+
Yumrepo['mongodb'] -> Package<| tag == 'mongodb_package' |>
2446
}
2547
}

0 commit comments

Comments
 (0)