1

Puppet is trying to start the service when the package is purged.

As a test I configured the package to be purged. But the service section is trying to start the zabbix-agent service. Any idea what went wrong?..

  package { 'zabbix-agent':
    name => $service_name,
    ensure => purged,
  }

  service { 'zabbix-agent':
    name => $service_name,
    ensure => running,
    enable => true,
    require => Package['zabbix-agent'],
    subscribe => File['zabbix-agentd.conf'],
  }

puppet agent -t output:

Error: Could not start Service[zabbix-agent]: Execution of '/bin/systemctl start zabbix-agent' returned 5: Failed to start zabbix-agent.service: Unit zabbix-agent.service not found.
Error: /Stage[main]/Zabbix/Service[zabbix-agent]/ensure: change from stopped to running failed: Could not start Service[zabbix-agent]: Execution of '/bin/systemctl start zabbix-agent' returned 5: Failed to start zabbix-agent.service: Unit zabbix-agent.service not found.
Notice: Finished catalog run in 0.25 seconds
user630702
  • 2,529
  • 5
  • 35
  • 98
  • That Puppet code will instruct the Puppet agent to purge the `zabbix-agent` package and then start the `zabbix-agent` service. That is also what you claim is occurring. What difference were you expecting? – Matthew Schuchard May 12 '20 at 11:00
  • I thought the service section would only run if the Package require is present. But that's not case. It seems Service section doesn't know anything about Package status but it'll only know if the Package section completed (in this case purging the package) and then service section proceeds to start the service. – user630702 May 12 '20 at 17:56

1 Answers1

1

When you enforce zabbix-agent to be running, you also need the package, so your package enforcement needs to be present.

  package { 'zabbix-agent':
    name   => $service_name,
    ensure => present,
  }

  service { 'zabbix-agent':
    name      => $service_name,
    ensure    => running,
    enable    => true,
    require   => Package['zabbix-agent'],
    subscribe => File['zabbix-agentd.conf'],
  }

If you also want to have the capability of purging, that would come in a different class (e.g.:

class zabbix::purge {
  package { 'zabbix-agent':
    name   => $service_name,
    ensure => purged,
  }

  service { 'zabbix-agent':
    name   => $service_name,
    ensure => false,
  }
}

As a consequence, you can't have both classes enforced to the same node, as you can't have the service in both states in the same time: running and purged.

azbarcea
  • 3,323
  • 1
  • 20
  • 25