Reputation: 767
I created a ntp module where I started a service and then I want to stop it. I wrote the entire code in a single ntp.pp
file. Did writing the code in a single file create this problem?
My code is:
package { 'ntp': ensure => installed }
service { 'ntp-run':
name => 'ntpd',
ensure => running,
require => Package['ntp'],
}
file { '/tmp/classtest': ensure => file }
file { '/tmp/ntplink':
ensure => link,
target => '/tmp/classtest',
require => File['/tmp/classtest'],
}
file { '/tmp/classdir': ensure => directory }
exec { '/tmp/classtest':
command => "mv /tmp/classtest /tmp/classdir",
path => '/bin/mv',
require => File['/tmp/classtest'],
}
service { 'ntp-stop':
ensure => stopped,
require => Service['ntp-run'],
}
package { 'ntp': ensure => absent }
file { '/tmp/classtest':
ensure => absent,
require => Exec['/tmp/classtest'],
}
but I am getting this error:
Error: Duplicate declaration: Package[ntp] is already declared in file /etc/puppet/ntp.pp:3; cannot redeclare at /etc/puppet/ntp.pp:34 on node ip-172-31-41-100.us-west-2.compute.internal
Error: Duplicate declaration: Package[ntp] is already declared in file /etc/puppet/ntp.pp:3; cannot redeclare at /etc/puppet/ntp.pp:34 on node ip-172-31-41-100.us-west-2.compute.internal
Upvotes: 0
Views: 636
Reputation: 15472
The error is because you have the same package managed on line 34 and on line 1. Puppet is not a scripting language, but is a declarative language intended to model only the end state of a system's configuration. What you're trying to do could be better accomplished using something like Ansible.
Upvotes: 1