Skip to content

Commit c0c2be8

Browse files
remicalixtetruthbk
authored andcommitted
Avoid potential dependency cycles when used with other modules (DataDog#463)
* Use native pgp key support of the apt module * apt::source notify apt_update by default * require Class['apt::update'] as the documentation suggests: https://github.com/puppetlabs/puppetlabs-apt\#adding-new-sources-or-ppas * Use 'exec' instead of 'ensure_packages' to break a dependencies cycle with some other modules * Fix spec tests * Set $key to empty dict if skipping apt key trusting
1 parent 7616b63 commit c0c2be8

4 files changed

Lines changed: 30 additions & 41 deletions

File tree

manifests/ubuntu/agent5.pp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525
Optional[String] $apt_keyserver = undef,
2626
) inherits datadog_agent::params{
2727

28-
ensure_packages(['apt-transport-https'])
28+
exec { 'apt-transport-https':
29+
command => '/usr/bin/apt-get install -y -q apt-transport-https'
30+
}
2931

3032
if !$skip_apt_key_trusting {
31-
::datadog_agent::ubuntu::install_key { [$apt_key]:
32-
server => $apt_keyserver,
33-
before => Apt::Source['datadog'],
33+
$key = {
34+
'id' => $apt_key,
35+
'server' => $apt_keyserver
3436
}
37+
} else {
38+
$key = {}
3539
}
3640

3741
# This is a hack - I'm not happy about it, but we should rarely
@@ -67,8 +71,9 @@
6771
location => $location,
6872
release => $release,
6973
repos => $repos,
70-
require => Package['apt-transport-https'],
71-
notify => [Exec['datadog_apt-get_remove_agent6'],Exec['apt_update']],
74+
key => $key,
75+
require => Exec['apt-transport-https'],
76+
notify => Exec['datadog_apt-get_remove_agent6'],
7277
}
7378

7479
package { 'datadog-agent-base':
@@ -79,7 +84,7 @@
7984
package { $datadog_agent::params::package_name:
8085
ensure => $agent_version,
8186
require => [Apt::Source['datadog'],
82-
Exec['apt_update']],
87+
Class['apt::update']],
8388
}
8489

8590
if $service_provider {

manifests/ubuntu/agent6.pp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
Optional[String] $apt_keyserver = undef,
1717
) inherits datadog_agent::params {
1818

19-
ensure_packages(['apt-transport-https'])
19+
exec { 'apt-transport-https':
20+
command => '/usr/bin/apt-get install -y -q apt-transport-https'
21+
}
22+
2023
if !$skip_apt_key_trusting {
21-
::datadog_agent::ubuntu::install_key { [$apt_key]:
22-
server => $apt_keyserver,
23-
before => Apt::Source['datadog6'],
24+
$key = {
25+
'id' => $apt_key,
26+
'server' => $apt_keyserver
2427
}
28+
} else {
29+
$key = {}
2530
}
2631

2732
apt::source { 'datadog':
@@ -33,8 +38,8 @@
3338
location => $location,
3439
release => $release,
3540
repos => $repos,
36-
require => Package['apt-transport-https'],
37-
notify => Exec['apt_update'],
41+
key => $key,
42+
require => Exec['apt-transport-https'],
3843
}
3944

4045
package { 'datadog-agent-base':
@@ -45,7 +50,7 @@
4550
package { $datadog_agent::params::package_name:
4651
ensure => $agent_version,
4752
require => [Apt::Source['datadog6'],
48-
Exec['apt_update']],
53+
Class['apt::update']],
4954
}
5055

5156
if $service_provider {

manifests/ubuntu/install_key.pp

Lines changed: 0 additions & 20 deletions
This file was deleted.

spec/classes/datadog_agent_ubuntu_spec.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
end
1717

1818
# it should install the mirror
19-
it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') }
19+
it { should_not contain_apt__key('Add key: 935F5A436A5A6E8788F0765B226AE980C7A7DA52 from Apt::Source datadog') }
2020
it do
21-
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
21+
should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog')
2222
end
2323
context 'overriding keyserver' do
2424
let(:params) {{
2525
apt_keyserver: 'hkp://pool.sks-keyservers.net:80',
2626
}}
2727
it do
28-
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
28+
should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog')\
2929
.with_server('hkp://pool.sks-keyservers.net:80')
3030
end
3131
end
@@ -38,7 +38,7 @@
3838

3939
# it should install the packages
4040
it do
41-
should contain_package('apt-transport-https')\
41+
should contain_exec('apt-transport-https')\
4242
.that_comes_before('file[/etc/apt/sources.list.d/datadog.list]')
4343
end
4444
it do
@@ -91,8 +91,7 @@
9191
end
9292

9393
# it should install the mirror
94-
it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') }
95-
it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') }
94+
it { should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog6') }
9695

9796
it do
9897
should contain_file('/etc/apt/sources.list.d/datadog6.list')\
@@ -102,7 +101,7 @@
102101

103102
# it should install the packages
104103
it do
105-
should contain_package('apt-transport-https')\
104+
should contain_exec('apt-transport-https')\
106105
.that_comes_before('file[/etc/apt/sources.list.d/datadog6.list]')
107106
end
108107
it do

0 commit comments

Comments
 (0)