diff --git a/manifests/ubuntu/agent5.pp b/manifests/ubuntu/agent5.pp index 43e506f5..0f1997b8 100644 --- a/manifests/ubuntu/agent5.pp +++ b/manifests/ubuntu/agent5.pp @@ -25,17 +25,13 @@ Optional[String] $apt_keyserver = undef, ) inherits datadog_agent::params{ - exec { 'apt-transport-https': - command => '/usr/bin/apt-get install -y -q apt-transport-https' - } + ensure_packages(['apt-transport-https']) if !$skip_apt_key_trusting { - $key = { - 'id' => $apt_key, - 'server' => $apt_keyserver + ::datadog_agent::ubuntu::install_key { [$apt_key]: + server => $apt_keyserver, + before => Apt::Source['datadog'], } - } else { - $key = {} } # This is a hack - I'm not happy about it, but we should rarely @@ -71,9 +67,8 @@ location => $location, release => $release, repos => $repos, - key => $key, - require => Exec['apt-transport-https'], - notify => Exec['datadog_apt-get_remove_agent6'], + require => Package['apt-transport-https'], + notify => [Exec['datadog_apt-get_remove_agent6'],Exec['apt_update']], } package { 'datadog-agent-base': @@ -84,7 +79,7 @@ package { $datadog_agent::params::package_name: ensure => $agent_version, require => [Apt::Source['datadog'], - Class['apt::update']], + Exec['apt_update']], } if $service_provider { diff --git a/manifests/ubuntu/agent6.pp b/manifests/ubuntu/agent6.pp index 7ef064c2..695f4ae8 100644 --- a/manifests/ubuntu/agent6.pp +++ b/manifests/ubuntu/agent6.pp @@ -16,17 +16,12 @@ Optional[String] $apt_keyserver = undef, ) inherits datadog_agent::params { - exec { 'apt-transport-https': - command => '/usr/bin/apt-get install -y -q apt-transport-https' - } - + ensure_packages(['apt-transport-https']) if !$skip_apt_key_trusting { - $key = { - 'id' => $apt_key, - 'server' => $apt_keyserver + ::datadog_agent::ubuntu::install_key { [$apt_key]: + server => $apt_keyserver, + before => Apt::Source['datadog6'], } - } else { - $key = {} } apt::source { 'datadog': @@ -38,8 +33,8 @@ location => $location, release => $release, repos => $repos, - key => $key, - require => Exec['apt-transport-https'], + require => Package['apt-transport-https'], + notify => Exec['apt_update'], } package { 'datadog-agent-base': @@ -50,7 +45,7 @@ package { $datadog_agent::params::package_name: ensure => $agent_version, require => [Apt::Source['datadog6'], - Class['apt::update']], + Exec['apt_update']], } if $service_provider { diff --git a/manifests/ubuntu/install_key.pp b/manifests/ubuntu/install_key.pp new file mode 100644 index 00000000..0c770213 --- /dev/null +++ b/manifests/ubuntu/install_key.pp @@ -0,0 +1,20 @@ +# Resource type: datadog_agent::ubuntu::install_key +# +# This resource type install repository keys in Ubuntu +# +# Parameters: +# +# Actions: +# +# Requires: +# +# Sample Usage: +# +# +# +define datadog_agent::ubuntu::install_key($server) { + apt::key { $name: + id => $name, + server => $server, + } +} diff --git a/spec/classes/datadog_agent_ubuntu_spec.rb b/spec/classes/datadog_agent_ubuntu_spec.rb index 27139f65..da68ed30 100644 --- a/spec/classes/datadog_agent_ubuntu_spec.rb +++ b/spec/classes/datadog_agent_ubuntu_spec.rb @@ -16,16 +16,16 @@ end # it should install the mirror - it { should_not contain_apt__key('Add key: 935F5A436A5A6E8788F0765B226AE980C7A7DA52 from Apt::Source datadog') } + it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') } it do - should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog') + should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\ end context 'overriding keyserver' do let(:params) {{ apt_keyserver: 'hkp://pool.sks-keyservers.net:80', }} it do - should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog')\ + should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\ .with_server('hkp://pool.sks-keyservers.net:80') end end @@ -38,7 +38,7 @@ # it should install the packages it do - should contain_exec('apt-transport-https')\ + should contain_package('apt-transport-https')\ .that_comes_before('file[/etc/apt/sources.list.d/datadog.list]') end it do @@ -91,7 +91,8 @@ end # it should install the mirror - it { should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog6') } + it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') } + it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') } it do should contain_file('/etc/apt/sources.list.d/datadog6.list')\ @@ -101,7 +102,7 @@ # it should install the packages it do - should contain_exec('apt-transport-https')\ + should contain_package('apt-transport-https')\ .that_comes_before('file[/etc/apt/sources.list.d/datadog6.list]') end it do