我创建了一个ntp模块,我启动了一个服务,然后我想停止它。我在一个ntp.pp
文件中编写了整个代码。将代码写入单个文件是否会产生此问题?
我的代码是:
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'],
}
但是我收到了这个错误:
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
答案 0 :(得分:1)
错误是因为您拥有在第34行和第1行管理的相同包.Puppet不是脚本语言,而是一种声明性语言,仅用于模拟系统配置的最终状态。使用像Ansible这样的东西可以更好地完成你想要做的事情。