Puppet - 服务在开始不工作之前需要包
Puppet - Service require package before starting not working
Puppet 正在尝试在包被清除时启动服务。
作为测试,我配置了要清除的包。但是service部分正在尝试启动zabbix-agent服务。知道哪里出了问题吗?..
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
输出:
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
当您强制 zabbix-agent
为 运行 时,您还需要包,因此您的包强制需要 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'],
}
如果您还想拥有 purging
的功能,那将采用不同的 class(例如:
class zabbix::purge {
package { 'zabbix-agent':
name => $service_name,
ensure => purged,
}
service { 'zabbix-agent':
name => $service_name,
ensure => false,
}
}
因此,您不能将两个 class 强制执行到同一节点,因为您不能同时在两个状态下使用该服务:running
和 purged
。
Puppet 正在尝试在包被清除时启动服务。
作为测试,我配置了要清除的包。但是service部分正在尝试启动zabbix-agent服务。知道哪里出了问题吗?..
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
输出:
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
当您强制 zabbix-agent
为 运行 时,您还需要包,因此您的包强制需要 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'],
}
如果您还想拥有 purging
的功能,那将采用不同的 class(例如:
class zabbix::purge {
package { 'zabbix-agent':
name => $service_name,
ensure => purged,
}
service { 'zabbix-agent':
name => $service_name,
ensure => false,
}
}
因此,您不能将两个 class 强制执行到同一节点,因为您不能同时在两个状态下使用该服务:running
和 purged
。