Skip to content

Commit

Permalink
Fix legacy Facts (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
cocker-cc authored Oct 26, 2023
1 parent ded74e0 commit 3de85cd
Show file tree
Hide file tree
Showing 20 changed files with 410 additions and 133 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ To enable the Datadog Agent Network Performance Monitoring (NPM) features follow
```conf
class { 'datadog_agent::system_probe':
network_enabled => true,
network_enabled => true,
}
```
Expand All @@ -214,7 +214,7 @@ To enable the Datadog Agent Universal Service Monitoring (USM) use the `datadog_
```conf
class { 'datadog_agent::system_probe':
service_monitoring_enabled => true,
service_monitoring_enabled => true,
}
```
Expand Down Expand Up @@ -276,7 +276,7 @@ To generate tags from custom facts classify your nodes with Puppet facts as an a
```conf
class { "datadog_agent":
api_key => "<YOUR_DD_API_KEY>",
facts_to_tags => ["osfamily","networking.domain","my_custom_fact"],
facts_to_tags => ["os.family","networking.domain","my_custom_fact"],
}
```
Expand Down
12 changes: 6 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
fail("agent_major_version must be either 5, 6 or 7, not ${_agent_major_version}")
}

if ($::operatingsystem == 'Windows' and $windows_ddagentuser_name != undef) {
if ($facts['os']['name'] == 'Windows' and $windows_ddagentuser_name != undef) {
$dd_user = $windows_ddagentuser_name
} else {
$dd_user = $datadog_agent::params::dd_user
Expand Down Expand Up @@ -423,7 +423,7 @@

# Install agent
if $manage_install {
case $::operatingsystem {
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':
Expand Down Expand Up @@ -477,7 +477,7 @@
rpm_repo_gpgcheck => $rpm_repo_gpgcheck,
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
}
} else {
if ! defined(Package[$agent_flavor]) {
Expand All @@ -496,7 +496,7 @@
service_provider => $service_provider,
}

if ($::operatingsystem != 'Windows') {
if ($facts['os']['name'] != 'Windows') {
if ($dd_groups) {
user { $dd_user:
groups => $dd_groups,
Expand All @@ -516,7 +516,7 @@

if $_agent_major_version == 5 {

if ($::operatingsystem == 'Windows') {
if ($facts['os']['name'] == 'Windows') {
fail('Installation of agent 5 with puppet is not supported on Windows')
}

Expand Down Expand Up @@ -752,7 +752,7 @@
$agent_config = deep_merge($_agent_config, $extra_config)


if ($::operatingsystem == 'Windows') {
if ($facts['os']['name'] == 'Windows') {


file { 'C:/ProgramData/Datadog':
Expand Down
2 changes: 1 addition & 1 deletion manifests/integrations/haproxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
class datadog_agent::integrations::haproxy(
$creds = {},
$url = "http://${::ipaddress}:8080",
$url = "http://${facts['networking']['ip']}:8080",
$options = {},
Optional[Array] $instances = undef
) inherits datadog_agent::params {
Expand Down
2 changes: 1 addition & 1 deletion manifests/integrations/ssh.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#

class datadog_agent::integrations::ssh(
$host = $::fqdn,
$host = $trusted['certname'],
$port = 22,
$username = $datadog_agent::dd_user,
$password = undef,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$securityagent_service_name = 'datadog-agent-security'
$module_metadata = load_module_metadata($module_name)

case $::operatingsystem {
case $facts['os']['name'] {
'Ubuntu','Debian','Raspbian' : {
$rubydev_package = 'ruby-dev'
case $::operatingsystemrelease{
Expand Down Expand Up @@ -83,7 +83,7 @@
$permissions_protected_file = '0660' # as bug in: https://tickets.puppetlabs.com/browse/PA-2877
$agent_binary = 'C:/Program Files/Datadog/Datadog Agent/embedded/agent.exe'
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${facts['os']['name']}") }
}

}
10 changes: 5 additions & 5 deletions manifests/redhat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
$repo_gpgcheck = $rpm_repo_gpgcheck
} else {
if ($agent_repo_uri == undef) and ($agent_major_version > 5) {
case $::operatingsystem {
case $facts['os']['name'] {
'RedHat', 'CentOS', 'OracleLinux': {
# disable repo_gpgcheck on 8.1 because of https://bugzilla.redhat.com/show_bug.cgi?id=1792506
if $::operatingsystemrelease =~ /^8.1/ {
if $facts['os']['release']['full'] =~ /^8.1/ {
$repo_gpgcheck = false
} else {
$repo_gpgcheck = true
Expand All @@ -46,15 +46,15 @@

case $agent_major_version {
5 : {
$defaulturl = "https://yum.datadoghq.com/rpm/${::architecture}/"
$defaulturl = "https://yum.datadoghq.com/rpm/${facts['os']['architecture']}/"
$gpgkeys = $keys
}
6 : {
$defaulturl = "https://yum.datadoghq.com/stable/6/${::architecture}/"
$defaulturl = "https://yum.datadoghq.com/stable/6/${facts['os']['architecture']}/"
$gpgkeys = $keys
}
7 : {
$defaulturl = "https://yum.datadoghq.com/stable/7/${::architecture}/"
$defaulturl = "https://yum.datadoghq.com/stable/7/${facts['os']['architecture']}/"
$gpgkeys = $keys
}
default: { fail('invalid agent_major_version') }
Expand Down
2 changes: 1 addition & 1 deletion manifests/reports.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$puppet_gem_provider = $datadog_agent::params::gem_provider,
) inherits datadog_agent::params {

if ($::operatingsystem == 'Windows') {
if ($facts['os']['name'] == 'Windows') {

fail('Reporting is not yet supported from a Windows host')

Expand Down
2 changes: 1 addition & 1 deletion manifests/security_agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
}

if $::operatingsystem == 'Windows' {
if $facts['os']['name'] == 'Windows' {

file { 'C:/ProgramData/Datadog/security-agent.yaml':
owner => $datadog_agent::params::dd_user,
Expand Down
2 changes: 1 addition & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
String $agent_flavor = $datadog_agent::params::package_name,
) inherits datadog_agent::params {

if ($::operatingsystem == 'Windows') {
if ($facts['os']['name'] == 'Windows') {
service { $datadog_agent::params::service_name:
ensure => $service_ensure,
enable => $service_enable,
Expand Down
4 changes: 2 additions & 2 deletions manifests/suse.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if ($agent_repo_uri != undef) {
$baseurl = $agent_repo_uri
} else {
$baseurl = "https://yum.datadoghq.com/suse/${release}/${agent_major_version}/${::architecture}"
$baseurl = "https://yum.datadoghq.com/suse/${release}/${agent_major_version}/${facts['os']['architecture']}"
}

package { 'datadog-agent-base':
Expand Down Expand Up @@ -78,7 +78,7 @@
name => 'datadog',
gpgcheck => 1,
# zypper on SUSE < 15 only understands a single gpgkey value
gpgkey => (Float($::operatingsystemmajrelease) >= 15.0) ? { true => join($gpgkeys, "\n "), default => $current_key },
gpgkey => (Float($facts['os']['release']['full']) >= 15.0) ? { true => join($gpgkeys, "\n "), default => $current_key },
# TODO: when updating zypprepo to 4.0.0, uncomment the repo_gpgcheck line
# For now, we can leave this commented, as zypper by default does repodata
# signature checks if the repomd.xml.asc is present, so repodata checks
Expand Down
4 changes: 2 additions & 2 deletions manifests/system_probe.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Class: datadog_agent::system_probe
#
# This class contains the Datadog agent system probe (NPM) configuration.
# On Windows, install the NPM driver by setting 'windows_npm_install'
# On Windows, install the NPM driver by setting 'windows_npm_install'
# to 'true on the datadog_agent class.
#

Expand Down Expand Up @@ -36,7 +36,7 @@
'runtime_security_config' => $runtime_security_config,
}

if $::operatingsystem == 'Windows' {
if $facts['os']['name'] == 'Windows' {
file { 'C:/ProgramData/Datadog/system-probe.yaml':
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
Expand Down
4 changes: 2 additions & 2 deletions manifests/ubuntu.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
}
}

if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16') == -1) or
($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '9') == -1) {
if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '16') == -1) or
($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'], '9') == -1) {
file { $apt_trusted_d_keyring:
mode => '0644',
source => "file://${apt_usr_share_keyring}",
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/datadog_agent_integrations_haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" }
let(:facts) do
{
ipaddress: '1.2.3.4',
networking: { 'ip' => '1.2.3.4' },
}
end

Expand Down
88 changes: 63 additions & 25 deletions spec/classes/datadog_agent_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
'release' => {
'major' => '36',
'full' => '36',
},
},
}
end

Expand Down Expand Up @@ -58,9 +64,15 @@
context 'agent 6' do
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
'release' => {
'major' => '36',
'full' => '36',
},
},
}
end

Expand Down Expand Up @@ -108,9 +120,15 @@
context 'agent 7' do
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
'release' => {
'major' => '36',
'full' => '36',
},
},
}
end

Expand Down Expand Up @@ -160,10 +178,15 @@
# we expect repo_gpgcheck to be false on 8.1
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'RedHat',
operatingsystemrelease: '8.1',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'RedHat',
'release' => {
'major' => '8',
'full' => '8.1',
},
},
}
end

Expand Down Expand Up @@ -193,10 +216,15 @@
# we expect repo_gpgcheck to be true on 8.2 (and later)
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'RedHat',
operatingsystemrelease: '8.2',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'RedHat',
'release' => {
'major' => '8',
'full' => '8.2',
},
},
}
end

Expand Down Expand Up @@ -226,10 +254,15 @@
context 'almalinux 8', if: min_puppet_version('7.12.0') do
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'AlmaLinux',
operatingsystemrelease: '8.5',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'AlmaLinux',
'release' => {
'major' => '8',
'full' => '8.5',
},
},
}
end

Expand Down Expand Up @@ -258,10 +291,15 @@
context 'rocky 8', if: min_puppet_version('7.12.0') do
let(:facts) do
{
osfamily: 'redhat',
operatingsystem: 'Rocky',
operatingsystemrelease: '8.5',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Rocky',
'release' => {
'major' => '8',
'full' => '8.5',
},
},
}
end

Expand Down
Loading

0 comments on commit 3de85cd

Please sign in to comment.