Topsurfer
2012-Mar-29 07:41 UTC
[Puppet Users] Exec if file changed AND if other files exists on system
Hello, I have to modiy a manifest. Actuall it''s the restart of snmp-daemon if snmpd.conf is changed. ( File["FILESnmpd"] -> Exec["RESTARTSnmpd"]) New should be: If snmpd.conf is changed AND if binayA and binayB exists => Restart Snmpd => than: Restart ServiceA => than Restart ServiceB How can this be done in manifest? This is not working :-( if exists(("Path-toBinayrA) and (Path-to- BinaryB)) { File["FILESnmpd"] -> Exec["RESTARTSnmpd"] -> Exec ["RESTARTServiceA"] -> Exec ["RESTARTServiceB"] } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Mar-29 13:30 UTC
[Puppet Users] Re: Exec if file changed AND if other files exists on system
On Mar 29, 2:41 am, Topsurfer <Topsur...@gmx.de> wrote:> Hello, > I have to modiy a manifest. > Actuall it''s the restart of snmp-daemon if snmpd.conf is changed. > ( File["FILESnmpd"] -> Exec["RESTARTSnmpd"]) > > New should be: > > If snmpd.conf is changed AND if binayA and binayB exists => Restart > Snmpd => than: Restart ServiceA => than Restart ServiceB > > How can this be done in manifest? > > This is not working :-( > if exists(("Path-toBinayrA) and (Path-to- > BinaryB))What is the ''exists'' function? It is not a documented Puppet built- in. Anyway, it probably is not doing what you think, because Puppet functions run on the master, not the agent.> { > File["FILESnmpd"] -> Exec["RESTARTSnmpd"] -> Exec > ["RESTARTServiceA"] -> > Exec ["RESTARTServiceB"] > }It is always better when Puppet knows the intended state of the target node and manages it than when Puppet''s management scope overlaps some other agent''s and it has to figure out what that other agent has done. Also, it is almost always best to use the most specific Puppet resource types to manage your resources. In this case, that means service A and service B ought to be under direct Puppet management, and you should be using Service resources to control them. A skeletal framework for that might look like this: class services::snmp { package { "net-snmp": ensure => latest } file { "/etc/snmpd.conf": ensure => ''file'', requires => Package[net-snmp], # ... content / source } service { "snmpd": enable => true, ensure => running, hasstatus => true, hasrestart => true, requires => Package[''net-snmp''], listen => File[''/etc/snmpd.conf''] } } class services::serviceA { include "services::snmpd" # package, conffile config service { "serviceA": enable => true, ensure => running, hasstatus => true, hasrestart => true, requires => Package[''serviceA-package''], listen => Service[''snmpd''] } } class services::serviceB { include "services::serviceA" # package, conffile config service { "serviceB": enable => true, ensure => running, hasstatus => true, hasrestart => true, requires => Package[''serviceB-package''], listen => Service[''serviceA''] } } Note that that particular setup assumes that all nodes that have Service A should also have snmpd, and all nodes that have Service B should also have Service A, but other combinations could be allowed with a bit more work. Anyway, each node declares one or more of classes services::snmpd, services::serviceA, and services::serviceB, and the ''listen'' parameters provide the desired restarting, in the desired sequence. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.