voxpupuli / puppet-prometheus

Puppet module for prometheus
https://forge.puppet.com/puppet/prometheus
Apache License 2.0
60 stars 241 forks source link

`ensure => 'absent'` doesn't do what it should do #374

Closed albatrossflavour closed 5 years ago

albatrossflavour commented 5 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

class profile::soe::monitoring::new_relic (
  Boolean $enable = lookup('profile::soe::monitoring::new_relic::enable',Boolean,first,false),
) {

  $key = lookup('profile::soe::monitoring::new_relic::sensitive_license_key',Sensitive,first,undef)

  case $enable {
    true: {
      $ensure = 'latest'
      $package_repo_ensure = 'present'
      $service_ensure = 'running'
    }
    default: {
      $ensure = 'absent'
      $package_repo_ensure = 'absent'
      $service_ensure = 'stopped'
    }
  }

  class { 'newrelic_infra::agent':
    ensure              => $ensure,
    package_repo_ensure => $package_repo_ensure,
    service_ensure      => $service_ensure,
    license_key         => $key.unwrap,
  }
}

What are you seeing

If set to true, the agent installs perfectly fine and works. If set to false without ever being set to true, Centos 6 and Ubuntu 14 fail on the newreelic-infra service as the upstart config is not in place.

If set to false having once been set to true (to remove a node from monitoring) it works, but only after I added in the package_repo and service ensure statements.

What behaviour did you expect instead

Ideally, setting the following should ensure that the New Relic software isn't installed or running, irrespective of the previous state:

class { 'newreelic_infra::agent':
  ensure => 'absent',
}

Output log

ubuntu14 node that has never had new relic installed

14:06 # puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for ubuntu14.laptop.bandcamp.tv
Info: Applying configuration version 'puppetmaster-production-fe032af225c'
Error: /Stage[main]/Newrelic_infra::Agent/Service[newrelic-infra]: Could not evaluate: Could not find init script or upstart conf file for 'newrelic-infra'

results of just setting a node previously set to 'ensure => 'latest'toensure => 'absent'`

Systemd start for newrelic-infra failed!
journalctl log for newrelic-infra:
-- Logs begin at Thu 2019-09-26 16:23:49 AEST, end at Fri 2019-09-27 11:25:37 AEST. --
Sep 27 11:25:29 dashboard.lab.bandcamp.tv newrelic-infra[2035]: 2019/09/27 11:25:29 Orderly shutdown commenced
Sep 27 11:25:29 dashboard.lab.bandcamp.tv newrelic-infra[2035]: time="2019-09-27T11:25:29+10:00" level=info msg="Gracefully Exiting"
Sep 27 11:25:29 dashboard.lab.bandcamp.tv newrelic-infra[2035]: time="2019-09-27T11:25:29+10:00" level=info msg="Agent service manager shutdown completed successfully." component=AgentService service=newrelic-infra
Sep 27 11:25:29 dashboard.lab.bandcamp.tv systemd[1]: Stopping New Relic Infrastructure Agent...
Sep 27 11:25:29 dashboard.lab.bandcamp.tv systemd[1]: Stopped New Relic Infrastructure Agent.

It's still trying to manage the service, even though the software has been removed. It also leaves behind the repos.

Any additional information you'd like to impart

I'm going to have a stab at fixing this up myself, but wanted it recorded incase anyone else runs into it in the interim.

albatrossflavour commented 5 years ago

Damn it, I should check that I'm on the right tab before I raise an issue. Sorry!