From 1657210221f5e12e15acd7d7cbd3d9e1c4584d5a Mon Sep 17 00:00:00 2001 From: Nicolas Schweitzer Date: Tue, 4 Jul 2023 15:14:24 +0200 Subject: [PATCH] Update recipes to support amazonlinux 2023 installation (#896) * Update recipes to support amazonlinux 2023 installation * Move tweak for amazonlinux on recipe_helpers --- libraries/recipe_helpers.rb | 7 +++++++ recipes/_install-linux.rb | 7 ++++--- recipes/repository.rb | 16 ++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/libraries/recipe_helpers.rb b/libraries/recipe_helpers.rb index 2103be1c..db72c646 100644 --- a/libraries/recipe_helpers.rb +++ b/libraries/recipe_helpers.rb @@ -132,6 +132,10 @@ def cookbook_version(run_context) run_context.cookbook_collection['datadog'].version end + def systemd_platform?(node) + (node['platform'] == 'amazon' || node['platform_family'] == 'amazon') && node['platform_version'].to_i >= 2022 + end + def upstart_platform?(node) agent_major_version(node) > 5 && (((node['platform'] == 'amazon' || node['platform_family'] == 'amazon') && node['platform_version'].to_i != 2) || @@ -146,6 +150,9 @@ def service_provider(node) service_provider = Chef::Provider::Service.const_get(specified_provider) end service_provider + # Specific catch for Amazon Linux >= 2022 where Upstart doesn't work + elsif systemd_platform?(node) + Chef::Provider::Service::Systemd elsif upstart_platform?(node) Chef::Provider::Service::Upstart end diff --git a/recipes/_install-linux.rb b/recipes/_install-linux.rb index 4239f3bc..070e66f0 100644 --- a/recipes/_install-linux.rb +++ b/recipes/_install-linux.rb @@ -45,9 +45,10 @@ action :upgrade end when 'rhel', 'fedora', 'amazon' - if platform_family?('rhel') && node['platform_version'].to_i >= 8 && !platform?('amazon') || - platform_family?('fedora') && node['platform_version'].to_i >= 28 - # yum_package doesn't work on RHEL 8 and Fedora >= 28 + if (platform_family?('rhel') && node['platform_version'].to_i >= 8) || + (platform_family?('fedora') && node['platform_version'].to_i >= 28) || + (platform_family?('amazon') && node['platform_version'].to_i >= 2022) + # yum_package doesn't work on RHEL >= 8, Fedora >= 28 and AmazonLinux >=2022 # dnf_package only works on RHEL 8 / Fedora >= 28 if Chef 15+ is used dnf_package dd_agent_flavor do version dd_agent_version diff --git a/recipes/repository.rb b/recipes/repository.rb index 817adde8..edd1df80 100644 --- a/recipes/repository.rb +++ b/recipes/repository.rb @@ -174,16 +174,12 @@ def warn_deprecated_yumrepo_gpgkey end # Previous versions of the cookbook could create these repo files, make sure we remove it now - apt_repository 'datadog-beta' do - action :remove - end - - apt_repository 'datadog_apt_D75CEA17048B9ACBF186794B32637D44F14F620E' do - action :remove - end - - apt_repository 'datadog_apt_A2923DFF56EDA6E76E55E492D3A80E30382E94DE' do - action :remove + ['datadog-beta', + 'datadog_apt_D75CEA17048B9ACBF186794B32637D44F14F620E', + 'datadog_apt_A2923DFF56EDA6E76E55E492D3A80E30382E94DE'].each do |repo| + apt_repository repo do + action :remove + end end when 'rhel', 'fedora', 'amazon'