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, 2019 in Puppet by Rohan

recategorized Feb 9, 2019 by Kalgi 1,120 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, 2019 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 15, 2019 in Puppet by Hatim
598 views
0 votes
1 answer

Puppet: error "Name or service not known."

You get this error usually if agents ...READ MORE

answered Aug 1, 2019 in Puppet by Sirajul
• 59,230 points
756 views
0 votes
1 answer

Puppet: Error while trying to execute shell commands in Exec resource type

The default exec provider on *nix OSes ...READ MORE

answered Aug 2, 2019 in Puppet by Sirajul
• 59,230 points
3,143 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
+2 votes
1 answer
0 votes
1 answer

Error in PE-PostgreSQL installation : Puppet

When installing PE on machines with large amounts of ...READ MORE

answered Jul 31, 2019 in Puppet by Sirajul
• 59,230 points
918 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP