Skip to content

Commit

Permalink
Fixes to not conflict with Agent & remote updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tbavelier committed Nov 6, 2024
1 parent ea92ab9 commit 1f1f954
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 85 deletions.
167 changes: 95 additions & 72 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
Boolean $windows_npm_install = false,
Optional[String] $windows_ddagentuser_name = undef,
Optional[String] $windows_ddagentuser_password = undef,
Optional[String] $remote_updates = undef,
Boolean $remote_updates = $datadog_agent::params::remote_updates,
Optional[Enum['host', 'docker', 'all']] $apm_instrumentation_enabled = undef,
Optional[Array[String]] $apm_instrumentation_libraries = undef,
) inherits datadog_agent::params {
Expand Down Expand Up @@ -484,6 +484,7 @@
datadog_site => $datadog_site,
agent_major_version => $_agent_major_version,
agent_minor_version => $_agent_minor_version_full,
manage_agent_install => $manage_install,
installer_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
Expand Down Expand Up @@ -522,95 +523,111 @@
}
}

# If the agent is managed by the installer, we don't need to manage the agent installation
$_agent_managed_by_installer = ($datadog_installer_enabled and $remote_updates)

# Install agent
if $manage_install {
case $facts['os']['name'] {
'Ubuntu','Debian','Raspbian' : {
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
notify { 'apt keyserver arguments deprecation':
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
loglevel => 'warning',
if ! $_agent_managed_by_installer {
if $manage_install {
case $facts['os']['name'] {
'Ubuntu','Debian','Raspbian' : {
if $use_apt_backup_keyserver != undef or $apt_backup_keyserver != undef or $apt_keyserver != undef {
notify { 'apt keyserver arguments deprecation':
message => '$use_apt_backup_keyserver, $apt_backup_keyserver and $apt_keyserver are deprecated since version 3.13.0',
loglevel => 'warning',
}
}
class { 'datadog_agent::ubuntu':
agent_major_version => $_agent_major_version,
agent_version => $agent_full_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
}
}
class { 'datadog_agent::ubuntu':
agent_major_version => $_agent_major_version,
agent_version => $agent_full_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
release => $apt_release,
skip_apt_key_trusting => $skip_apt_key_trusting,
}
}
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
class { 'datadog_agent::redhat':
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
manage_repo => $manage_repo,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux','AlmaLinux','Rocky' : {
class { 'datadog_agent::redhat':
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
manage_repo => $manage_repo,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
}
'Windows' : {
class { 'datadog_agent::windows' :
agent_major_version => $_agent_major_version,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
msi_location => $win_msi_location,
api_key => $api_key,
hostname => $host,
tags => $local_tags,
ensure => $win_ensure,
npm_install => $windows_npm_install,
ddagentuser_name => $windows_ddagentuser_name,
ddagentuser_password => $windows_ddagentuser_password,
'Windows' : {
class { 'datadog_agent::windows' :
agent_major_version => $_agent_major_version,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
msi_location => $win_msi_location,
api_key => $api_key,
hostname => $host,
tags => $local_tags,
ensure => $win_ensure,
npm_install => $windows_npm_install,
ddagentuser_name => $windows_ddagentuser_name,
ddagentuser_password => $windows_ddagentuser_password,
}
if ($win_ensure == absent) {
return() #Config files will remain unchanged on uninstall
}
}
if ($win_ensure == absent) {
return() #Config files will remain unchanged on uninstall
'OpenSuSE', 'SLES' : {
class { 'datadog_agent::suse' :
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
}
'OpenSuSE', 'SLES' : {
class { 'datadog_agent::suse' :
agent_major_version => $_agent_major_version,
agent_flavor => $agent_flavor,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_full_version,
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
} else {
if ! defined(Package[$agent_flavor]) {
package { $agent_flavor:
ensure => present,
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
}
} else {
if ! defined(Package[$agent_flavor]) {
package { $agent_flavor:
ensure => present,
source => 'Agent installation not managed by Puppet, make sure the Agent is installed beforehand.',
}
}
}

# Declare service
class { 'datadog_agent::service' :
agent_flavor => $agent_flavor,
service_ensure => $service_ensure,
service_enable => $service_enable,
service_provider => $service_provider,
}
if ($facts['os']['name'] != 'Windows') {
if ($dd_groups) {
user { $dd_user:
groups => $dd_groups,
notify => Service[$datadog_agent::params::service_name],
if ! $_agent_managed_by_installer {
class { 'datadog_agent::service' :
agent_flavor => $agent_flavor,
service_ensure => $service_ensure,
service_enable => $service_enable,
service_provider => $service_provider,
}
if ($facts['os']['name'] != 'Windows') {
if ($dd_groups) {
user { $dd_user:
groups => $dd_groups,
notify => Service[$datadog_agent::params::service_name],
}
}
}

# required by reports even in agent5 scenario
# required by reports even in agent5 scenario
file { '/etc/datadog-agent':
ensure => directory,
owner => $dd_user,
group => $dd_group,
mode => $datadog_agent::params::permissions_directory,
require => Package[$agent_flavor],
}
}
} else {
# required to manage config and install info files even with installer
file { '/etc/datadog-agent':
ensure => directory,
owner => $dd_user,
group => $dd_group,
mode => $datadog_agent::params::permissions_directory,
require => Package[$agent_flavor],
require => Package['datadog-installer'],
}
}

Expand Down Expand Up @@ -846,7 +863,10 @@
force => $conf_dir_purge,
owner => $dd_user,
group => $dd_group,
notify => Service[$datadog_agent::params::service_name],
}

if ! $_agent_managed_by_installer {
File[$_conf_dir] ~> Service[$datadog_agent::params::service_name]
}

$_local_tags = datadog_agent::tag6($local_tags, false, undef)
Expand All @@ -868,6 +888,7 @@
'dogstatsd_non_local_traffic' => $non_local_traffic,
'log_file' => $agent_log_file,
'log_level' => $log_level,
'remote_updates' => $remote_updates,
'tags' => unique(flatten(union($_local_tags, $_facts_tags, $_trusted_facts_tags))),
}

Expand Down Expand Up @@ -906,9 +927,11 @@
mode => '0640',
content => template('datadog_agent/datadog.yaml.erb'),
show_diff => false,
notify => Service[$datadog_agent::params::service_name],
require => File['/etc/datadog-agent'],
}
if ! $_agent_managed_by_installer {
File['/etc/datadog-agent/datadog.yaml'] ~> Service[$datadog_agent::params::service_name]
}

file { '/etc/datadog-agent/install_info':
owner => $dd_user,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$process_default_custom_words = []
$logs_enabled = false
$logs_open_files_limit = undef
$remote_updates = false
$container_collect_all = false
$sysprobe_service_name = 'datadog-agent-sysprobe'
$securityagent_service_name = 'datadog-agent-security'
Expand Down
8 changes: 4 additions & 4 deletions manifests/redhat_installer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# @param rpm_repo_gpgcheck Optional[Boolean]: Whether to check the GPG signature of the repository.
# @param apm_instrumentation_enabled Optional[Enum['host', 'docker', 'all']]: Enable APM instrumentation for the specified environment (host, docker, or all).
# @param apm_instrumentation_libraries_str Optional[String]: APM instrumentation libraries as a comma-separated string.
# @param remote_updates Optional[String]: Whether to enable remote updates.
# @param remote_updates Boolean: Whether to enable Agent remote updates. Default: false.
#
class datadog_agent::redhat_installer (
String $api_key = 'your_API_key',
Expand All @@ -20,7 +20,7 @@
Optional[Boolean] $rpm_repo_gpgcheck = undef,
Optional[Enum['host', 'docker', 'all']] $apm_instrumentation_enabled = undef,
Optional[String] $apm_instrumentation_libraries_str = undef,
Optional[String] $remote_updates = undef,
Boolean $remote_updates = $datadog_agent::params::remote_updates,
) inherits datadog_agent::params {
# Generate installer trace ID as a random 64-bit integer (Puppet does not support 128-bit integers)
# Note: we cannot use fqdn_rand as the seed is dependent on the node, meaning the same trace ID would be generated on each run (for the same node)
Expand Down Expand Up @@ -80,7 +80,7 @@
$baseurl = "https://yum.datadoghq.com/stable/7/${facts['os']['architecture']}/"
}

yumrepo { 'datadog':
yumrepo { 'datadog-installer':
enabled => 1,
gpgcheck => 1,
gpgkey => join($all_keys, "\n "),
Expand All @@ -93,7 +93,7 @@
# Install `datadog-installer` package with latest versions
package { 'datadog-installer':
ensure => 'latest',
require => Yumrepo['datadog'],
require => Yumrepo['datadog-installer'],
}

# Bootstrap the installer
Expand Down
10 changes: 5 additions & 5 deletions manifests/suse_installer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# @param rpm_repo_gpgcheck Optional[Boolean]: Whether to check the GPG signature of the repository.
# @param apm_instrumentation_enabled Optional[Enum['host', 'docker', 'all']]: Enable APM instrumentation for the specified environment (host, docker, or all).
# @param apm_instrumentation_libraries_str Optional[String]: APM instrumentation libraries as a comma-separated string.
# @param remote_updates Optional[String]: Whether to enable remote updates.
# @param remote_updates Boolean: Whether to enable Agent remote updates. Default: false.
#
class datadog_agent::suse_installer (
String $api_key = 'your_API_key',
Expand All @@ -20,7 +20,7 @@
Optional[Boolean] $rpm_repo_gpgcheck = undef,
Optional[Enum['host', 'docker', 'all']] $apm_instrumentation_enabled = undef,
Optional[String] $apm_instrumentation_libraries_str = undef,
Optional[String] $remote_updates = undef,
Boolean $remote_updates = $datadog_agent::params::remote_updates,
) inherits datadog_agent::params {
# Generate installer trace ID as a random 64-bit integer (Puppet does not support 128-bit integers)
# Note: we cannot use fqdn_rand as the seed is dependent on the node, meaning the same trace ID would be generated on each run (for the same node)
Expand Down Expand Up @@ -85,11 +85,11 @@
}
}

zypprepo { 'datadog':
zypprepo { 'datadog-installer':
baseurl => $baseurl,
enabled => 1,
autorefresh => 1,
name => 'datadog',
name => 'datadog-installer',
gpgcheck => 1,
# zypper on SUSE < 15 only understands a single gpgkey value
gpgkey => (Float($facts['os']['release']['full']) >= 15.0) ? { true => join($all_keys, "\n "), default => 'https://keys.datadoghq.com/DATADOG_RPM_KEY_CURRENT.public' },
Expand All @@ -106,7 +106,7 @@
# Install `datadog-installer` package with latest versions
package { 'datadog-installer':
ensure => 'latest',
require => Zypprepo['datadog'],
require => Zypprepo['datadog-installer'],
}

# Bootstrap the installer
Expand Down
8 changes: 4 additions & 4 deletions manifests/ubuntu_installer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# @param apt_default_keys Hash[String, String]: A hash of default APT keys and their URLs.
# @param apm_instrumentation_enabled Optional[Enum['host', 'docker', 'all']]: Enable APM instrumentation for the specified environment (host, docker, or all).
# @param apm_instrumentation_libraries_str Optional[String]: APM instrumentation libraries as a comma-separated string.
# @param remote_updates Optional[String]: Whether to enable remote updates.
# @param remote_updates Boolean: Whether to enable Agent remote updates. Default: false.
#
class datadog_agent::ubuntu_installer (
String $api_key = 'your_API_key',
Expand Down Expand Up @@ -42,7 +42,7 @@
},
Optional[Enum['host', 'docker', 'all']] $apm_instrumentation_enabled = undef,
Optional[String] $apm_instrumentation_libraries_str = undef,
Optional[String] $remote_updates = undef,
Boolean $remote_updates = $datadog_agent::params::remote_updates,
) inherits datadog_agent::params {
# Generate installer trace ID as a random 64-bit integer (Puppet does not support 128-bit integers)
# Note: we cannot use fqdn_rand as the seed is dependent on the node, meaning the same trace ID would be generated on each run (for the same node)
Expand Down Expand Up @@ -109,7 +109,7 @@
}

# Install APT repository
apt::source { 'datadog installer':
apt::source { 'datadog-installer':
# Installer is located in the same APT repository as the Agent, only within repo 7
comment => 'Datadog Installer Repository',
location => $location,
Expand All @@ -121,7 +121,7 @@
# Install `datadog-installer` package with latest versions
package { 'datadog-installer':
ensure => 'latest',
require => [Apt::Source['datadog installer'], Class['apt::update']],
require => [Apt::Source['datadog-installer'], Class['apt::update']],
}

# Bootstrap the installer
Expand Down

0 comments on commit 1f1f954

Please sign in to comment.