diff --git a/.fixtures.yml b/.fixtures.yml index 7c6b108b..949dda2e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -16,6 +16,7 @@ fixtures: forge_modules: yumrepo_core: "puppetlabs/yumrepo_core" powershell: "puppetlabs/powershell" + zypprepo: "puppet/zypprepo" symlinks: custom_datadog: "#{source_dir}/spec/custom_fixtures/custom_datadog" datadog_agent: "#{source_dir}" diff --git a/environments/etc/Puppetfile b/environments/etc/Puppetfile index f705e446..190f8b4e 100644 --- a/environments/etc/Puppetfile +++ b/environments/etc/Puppetfile @@ -7,3 +7,4 @@ mod 'puppetlabs-ruby', '1.0.0' mod 'puppetlabs-stdlib', '4.24.0' mod 'puppetlabs-powershell', '2.3.0' mod 'puppetlabs-yumrepo_core', '1.0.3' +mod 'puppet-zypprepo', '3.1.0' diff --git a/environments/opensuse15/Vagrantfile b/environments/opensuse15/Vagrantfile new file mode 100644 index 00000000..90a5bc6d --- /dev/null +++ b/environments/opensuse15/Vagrantfile @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +Vagrant.configure("2") do |config| + config.vm.box = "generic/opensuse15" + config.vm.provision "file", source: "../../environments/etc", destination: "$HOME/puppet" + config.vm.synced_folder "../../", "/puppet-datadog-agent" + config.vm.provision "shell", inline: <<-SHELL + #install puppet 6 + zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo + zypper install -y puppet-agent + ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet + + # install modules + zypper install -y git + cd /home/vagrant/puppet + /opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7 + /opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/home/vagrant/puppet/modules + + # link local module + ln -s /puppet-datadog-agent /home/vagrant/puppet/modules/datadog_agent + SHELL +end diff --git a/kitchen.yml b/kitchen.yml index 42a58218..23292d84 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -66,6 +66,25 @@ platforms: - gem install r10k -v 2.6.7 - cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules + + - name: opensuse/leap-15 + driver_config: + # we use a custom image that runs systemd + image: 'datadog/docker-library:chef_kitchen_systemd_opensuse_leap_15' + run_command: /root/start.sh + + driver: + provision_command: + - zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo + - zypper install -y puppet-agent ruby=2.5 + - gem install bundler serverspec rspec + - ln -s /usr/bin/rspec.ruby2.5 /usr/bin/rspec + - ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet + - mkdir /home/kitchen/puppet + - printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile + + - /opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7 + - cd /home/kitchen/puppet && /opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/tmp/modules verifier: name: serverspec diff --git a/manifests/init.pp b/manifests/init.pp index 43140259..497fbf03 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -451,6 +451,13 @@ return() #Config files will remain unchanged on uninstall } } + 'OpenSuSE', 'SLES' : { + class { 'datadog_agent::suse' : + agent_major_version => $_agent_major_version, + agent_repo_uri => $agent_repo_uri, + agent_version => $agent_version, + } + } default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") } } } else { diff --git a/manifests/params.pp b/manifests/params.pp index 9ceada4a..0b7b9294 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -40,7 +40,7 @@ $permissions_protected_file = '0600' $agent_binary = '/opt/datadog-agent/bin/agent/agent' } - 'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux' : { + 'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux', 'OpenSuSE', 'SLES' : { $rubydev_package = 'ruby-devel' $legacy_conf_dir = '/etc/dd-agent/conf.d' $conf_dir = '/etc/datadog-agent/conf.d' diff --git a/manifests/suse.pp b/manifests/suse.pp new file mode 100644 index 00000000..f537d7f0 --- /dev/null +++ b/manifests/suse.pp @@ -0,0 +1,69 @@ +# Class: datadog_agent::suse +# +# This class contains the DataDog agent installation mechanism for SUSE distributions +# + +class datadog_agent::suse( + Integer $agent_major_version = $datadog_agent::params::default_agent_major_version, + String $agent_version = $datadog_agent::params::agent_version, + String $release = $datadog_agent::params::apt_default_release, + Optional[String] $agent_repo_uri = undef, +) inherits datadog_agent::params { + + $all_keys = [ + 'https://yum.datadoghq.com/DATADOG_RPM_KEY.public', + 'https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public', + 'https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public', + ] + + case $agent_major_version { + 5 : { fail('Agent v5 package not available in SUSE') } + 6 : { $gpgkeys = $all_keys } + 7 : { $gpgkeys = $all_keys[1,2] } + default: { fail('invalid agent_major_version') } + } + + if ($agent_repo_uri != undef) { + $baseurl = $agent_repo_uri + } else { + $baseurl = "https://yum.datadoghq.com/suse/${release}/${agent_major_version}/${::architecture}" + } + + package { 'datadog-agent-base': + ensure => absent, + before => Package[$datadog_agent::params::package_name], + } + + # We need to install GPG keys manually since zypper will autoreject new keys + # We download each key and import it using rpm --import + $gpgkeys.each |String $key_url| { + $key_name = split($key_url, '/') + $key_path = "/tmp/${key_name[-1]}" + + file { $key_path: + owner => root, + group => root, + mode => '0600', + source => $key_url, + } + + exec { "install-${key_name}": + command => "/bin/rpm --import ${key_path}", + } + } + + zypprepo { 'datadog': + baseurl => $baseurl, + enabled => 1, + autorefresh => 1, + name => 'datadog', + gpgcheck => 1, + gpgkey => join($gpgkeys, " "), + keeppackages => 1, + } + + package { $datadog_agent::params::package_name: + ensure => $agent_version, + } + +} diff --git a/metadata.json b/metadata.json index 9be9466f..e5f3cddc 100644 --- a/metadata.json +++ b/metadata.json @@ -35,6 +35,10 @@ { "name": "puppetlabs/powershell", "version_requirement": ">=2.3.0 <5.0.0" + }, + { + "name": "puppet/zypprepo", + "version_requirement": ">=3.1.0 <4.0.0" } ], "operatingsystem_support": [ @@ -114,6 +118,23 @@ "8", "10" ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11", + "12", + "15" + ] + }, + { + "operatingsystem": "OpenSUSE", + "operatingsystemrelease": [ + "11", + "12", + "13", + "15" + ] } ], "requirements": [ diff --git a/spec/classes/datadog_agent_suse_spec.rb b/spec/classes/datadog_agent_suse_spec.rb new file mode 100644 index 00000000..7309d4bb --- /dev/null +++ b/spec/classes/datadog_agent_suse_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'datadog_agent::suse' do + if RSpec::Support::OS.windows? + return + end + + let(:facts) do + { + operatingsystem: 'OpenSuSE', + architecture: 'x86_64', + } + end + + context 'agent 6' do + let(:params) do + { + agent_major_version: 6, + } + end + + it do + is_expected.to contain_zypprepo('datadog') + .with_enabled(1)\ + .with_gpgcheck(1)\ + .with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY.public https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public')\ + .with_baseurl('https://yum.datadoghq.com/suse/stable/6/x86_64') + end + end + + context 'agent 7' do + let(:params) do + { + agent_major_version: 7, + } + end + + it do + is_expected.to contain_zypprepo('datadog') + .with_enabled(1)\ + .with_gpgcheck(1)\ + .with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public')\ + .with_baseurl('https://yum.datadoghq.com/suse/stable/7/x86_64') + end + end + + # it should install the packages + it do + is_expected.to contain_package('datadog-agent')\ + .with_ensure('latest') + end +end