Skip to content

Commit

Permalink
Fix legacy Facts
Browse files Browse the repository at this point in the history
Since Puppet 4 “structured Facts” are available.
The “non-strucured Facts” are legacy and deprecated.
So this Commit is a Fix for that.

The legacy Facts are kept in Rspec-Tests for now, but can be deleted in
near Future.
  • Loading branch information
cocker-cc committed Oct 24, 2023
1 parent ded74e0 commit 85a669f
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 24 deletions.
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
1 change: 1 addition & 0 deletions spec/classes/datadog_agent_integrations_haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:facts) do
{
ipaddress: '1.2.3.4',
networking: { 'ip' => '1.2.3.4' },
}
end

Expand Down
39 changes: 39 additions & 0 deletions spec/classes/datadog_agent_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
},
}
end

Expand Down Expand Up @@ -61,6 +66,11 @@
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
},
}
end

Expand Down Expand Up @@ -111,6 +121,11 @@
osfamily: 'redhat',
operatingsystem: 'Fedora',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Fedora',
},
}
end

Expand Down Expand Up @@ -164,6 +179,12 @@
operatingsystem: 'RedHat',
operatingsystemrelease: '8.1',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'RedHat',
'release' => { 'full' => '8.1' },
},
}
end

Expand Down Expand Up @@ -197,6 +218,12 @@
operatingsystem: 'RedHat',
operatingsystemrelease: '8.2',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'RedHat',
'release' => { 'full' => '8.2' },
},
}
end

Expand Down Expand Up @@ -230,6 +257,12 @@
operatingsystem: 'AlmaLinux',
operatingsystemrelease: '8.5',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'AlmaLinux',
'release' => { 'full' => '8.5' },
},
}
end

Expand Down Expand Up @@ -262,6 +295,12 @@
operatingsystem: 'Rocky',
operatingsystemrelease: '8.5',
architecture: 'x86_64',
os: {
'architecture' => 'x86_64',
'family' => 'redhat',
'name' => 'Rocky',
'release' => { 'full' => '8.5' },
},
}
end

Expand Down
21 changes: 21 additions & 0 deletions spec/classes/datadog_agent_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
operatingsystem: operatingsystem,
osfamily: getosfamily(operatingsystem),
operatingsystemrelease: getosrelease(operatingsystem),
os: {
'family' => getosfamily(operatingsystem),
'name' => operatingsystem,
'release' => { 'full' => getosrelease(operatingsystem) },
},
}
end

Expand Down Expand Up @@ -83,6 +88,10 @@
{
operatingsystem: 'Debian',
osfamily: 'debian',
os: {
'family' => 'debian',
'name' => 'Debian',
},
}
end

Expand Down Expand Up @@ -125,6 +134,10 @@
{
operatingsystem: 'Debian',
osfamily: 'debian',
os: {
'family' => 'debian',
'name' => 'Debian',
},
}
end

Expand Down Expand Up @@ -162,6 +175,10 @@
{
operatingsystem: 'Debian',
osfamily: 'debian',
os: {
'family' => 'debian',
'name' => 'Debian',
},
}
end

Expand Down Expand Up @@ -201,6 +218,10 @@
{
operatingsystem: 'Debian',
osfamily: 'debian',
os: {
'family' => 'debian',
'name' => 'Debian',
},
}
end

Expand Down
Loading

0 comments on commit 85a669f

Please sign in to comment.