Service already defines error in Puppet

0 votes

I have this class

class MyClass{
    service{"ServiceName-start":
      name => "ServiceName",
      ensure => "stopped",
    }
    package{"PackageName":
        ensure => "installed",
        require => Service["ServiceName-Start"],
    }
    service{"ServiceName-Stop":
      name =>  "ServiceName",
      ensure => "running",
      require => Package["PackageName"]
    }
}

But I end up with an error:

Duplicate definition: Service[ServiceName] is already defined in file /puppet/mycsass.pp at line 2; cannot redefine at /puppet/myclass.pp:9

Feb 9 in Puppet by Rohan

recategorized Feb 9 by Kalgi 25 views

1 answer to this question.

0 votes

Hey @Rohan, try this:

class MyClass {
  exec { "ServiceName-Stop":
    command => "/bin/sh -c '/sbin/service ServiceName stop",
  }
  package{"PackageName":
    ensure => "installed",
    require => Service["ServiceName-Stop"],
  }
  service{"ServiceName-Start":
    name =>  "ServiceName",
    ensure => "running",
    require => Package["PackageName"]
  }
}
answered Feb 9 by Monish

Related Questions In Puppet

0 votes
1 answer

Pupper error - Duplicate definition: Service[ServiceName] is already defined

Hey @Nigya, try something like this: class MyClass ...READ MORE

answered Feb 14 in Puppet by Hatim
20 views
0 votes
1 answer
0 votes
1 answer

Error while using newrelic class - Puppet

Hey @Harjot, The catalog compiler will look ...READ MORE

answered Feb 14 in Puppet by Ranjan
18 views
0 votes
1 answer

What are profiles in Puppet?

Wrapper classes that use multiple component modules ...READ MORE

answered Feb 15 in Puppet by Sheela
13 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Can I access environment variables with Facter in Puppet?

Hey @Ruth, not directly. However, Facter reads ...READ MORE

answered Feb 15 in Puppet by Krishti

edited Feb 15 148 views
0 votes
1 answer