Hello Here is my manifest for snmpd, my problem now is that my manifest will run every time because my snmpd.conf file changes after the "exec"!! I want that my manifest run when the snmpd.conf (only snmpd.conf source and not with exec) file change or when my /etc/fstab file on the client change and it restart the snmpd service. I do not know if I''m very clear, but it is not easy to explain it in English . Did you have an idea? class snmpd::redhat { package { "net-snmp": ensure => present, } file { "/etc/snmp/snmpd.conf": ensure => present, owner => ''root'', group => ''root'', mode => 644, source => "puppet:///modules/snmpd/snmpd.conf", require=> Package["net-snmp"], notify => Exec["disk-snmp"] # notify => Service["snmpd"] } file { "/etc/fstab": ensure => present } exec { "disk-snmp": command => "grep -e \"ext[2-4]\" /etc/fstab|awk ''{print \"disk\",''$\2''}'' >> /etc/snmp/snmpd.conf", # subscribe => File["/etc/snmp/snmpd.conf"], subscribe => File["/etc/fstab"], path => ["/usr/bin", "/bin", "/usr/sbin"], notify => Service["snmpd"] } service { "snmpd": ensure => running, hasstatus => true, hasrestart => true, enable => true, require => File[''/etc/snmp/snmpd.conf''] } } my source : snmpd.conf : com2sec nagios 192.168.1.1 communaute view tout included .1 group collecte v1 cacti access collecte "" any noauth exact tout none none syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat Is it possible in my snmpd.conf source a solution as : com2sec nagios 192.168.1.1 communaute view tout included .1 group collecte v1 cacti access collecte "" any noauth exact tout none none syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat *Exec **["disk-snmp"]* -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
I am not positive exactly what you are trying to accomplish, but I believe you can do this in a couple of ways. First, if puppet manages snmpd.conf and /etc/fstab simply set "refreshonly => true" on the exec and set those two file resources to notify the exec. If puppet does not manage those files, or only partially managed them, it will be more complicated but it is still doable. In this case, you would need to make use of ''unless'' or ''onlyif'' to determine if the command needs to be ran. See http://docs.puppetlabs.com/references/3.2.latest/type.html#exec for more details. If the command to use as a test is complicated, I would suggest writing a shell script and pushing the file out with a file resource and then executing the script in the unless or only if. On Thursday, May 30, 2013 12:32:05 PM UTC-5, Stan wrote:> > Hello > > Here is my manifest for snmpd, my problem now is that my manifest will run > every time because my snmpd.conf file changes after the "exec"!! I want > that my manifest run when the snmpd.conf (only snmpd.conf source and not > with exec) file change or when my /etc/fstab file on the client changeand > it restart the snmpd service. > > > I do not know if I''m very clear, but it is not easy to explain it in > English. > > Did you have an idea? > > class snmpd::redhat { > package { "net-snmp": > ensure => present, > } > > file { "/etc/snmp/snmpd.conf": > ensure => present, > owner => ''root'', > group => ''root'', > mode => 644, > source => "puppet:///modules/snmpd/snmpd.conf", > require=> Package["net-snmp"], > notify => Exec["disk-snmp"] > # notify => Service["snmpd"] > } > > > file { "/etc/fstab": > ensure => present > } > > > exec { "disk-snmp": > command => "grep -e \"ext[2-4]\" /etc/fstab|awk ''{print > \"disk\",''$\2''}'' >> /etc/snmp/snmpd.conf", > # subscribe => File["/etc/snmp/snmpd.conf"], > subscribe => File["/etc/fstab"], > path => ["/usr/bin", "/bin", "/usr/sbin"], > notify => Service["snmpd"] > } > > > service { "snmpd": > ensure => running, > hasstatus => true, > hasrestart => true, > enable => true, > require => File[''/etc/snmp/snmpd.conf''] > } > } > > > my source : snmpd.conf : > > com2sec nagios 192.168.1.1 communaute > view tout included .1 > group collecte v1 cacti > access collecte "" any noauth exact tout none none > syslocation Unknown (edit /etc/snmp/snmpd.conf) > syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) > pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat > > > > Is it possible in my snmpd.conf source a solution as : > > com2sec nagios 192.168.1.1 communaute > view tout included .1 > group collecte v1 cacti > access collecte "" any noauth exact tout none none > syslocation Unknown (edit /etc/snmp/snmpd.conf) > syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) > pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat > *Exec **["disk-snmp"]* >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Stan, You could try setting refreshonly to ''true'' in the exec, that way it will only run when the /etc/fstab file it is subscribed to changes. However, I don''t know if this will work as you''re only ensuring the file is present. http://docs.puppetlabs.com/references/latest/type.html#exec Alternatively, you could add disk information in a separate configuration file (say, /etc/snmp/snmpd.conf.disk) that is included by the main configuration using an include directive, like this: include "/etc/snmp/snmpd.conf.disk" And then change your exec resource to output the result to /etc/snmp/snmpd.conf.disk instead. Hope that helps, Bill On 05/30/2013 01:32 PM, Stan wrote: -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlGnk9QACgkQ5xgg9J6hpUthFgCfUSFpOSoieOxfujGgZhMZp5Qo +yoAn37BL1lFkwiA/o/jzfyOS0qizM8C =QWOk -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Stan, You could try setting refreshonly to ''true'' in the exec, that way it will only run when the /etc/fstab file it is subscribed to changes. However, I don''t know if this will work as you''re only ensuring the file is present. http://docs.puppetlabs.com/references/latest/type.html#exec Alternatively, you could add disk information in a separate configuration file (say, /etc/snmp/snmpd.conf.disk) that is included by the main configuration using an include directive, like this: include "/etc/snmp/snmpd.conf.disk" And then change your exec resource to output the result to /etc/snmp/snmpd.conf.disk instead. Hope that helps, Bill On 05/30/2013 01:32 PM, Stan wrote:> Hello > > Here is my manifest for snmpd, my problem now is that my manifest > will run every time because my snmpd.conf file changes after the > "exec"!! I want that my manifest run when the snmpd.conf (only > snmpd.conf source and not with exec) file change or when my > /etc/fstab file on the client change and it restart the snmpd > service. > > > I do not know if I''m very clear, but it is not easy to explain it > in English. > > Did you have an idea? > > class snmpd::redhat { package { "net-snmp": ensure => present, } > > file { "/etc/snmp/snmpd.conf": ensure => present, owner => ''root'', > group => ''root'', mode => 644, source => > "puppet:///modules/snmpd/snmpd.conf", require=> > Package["net-snmp"], notify => Exec["disk-snmp"] # notify => > Service["snmpd"] } > > > file { "/etc/fstab": ensure => present } > > > exec { "disk-snmp": command => "grep -e \"ext[2-4]\" > /etc/fstab|awk ''{print \"disk\",''$\2''}'' >> /etc/snmp/snmpd.conf", > # subscribe => File["/etc/snmp/snmpd.conf"], subscribe => > File["/etc/fstab"], path => ["/usr/bin", "/bin", "/usr/sbin"], > notify => Service["snmpd"] } > > > service { "snmpd": ensure => running, hasstatus => true, > hasrestart => true, enable => true, require => > File[''/etc/snmp/snmpd.conf''] } } > > > my source : snmpd.conf : > > com2sec nagios 192.168.1.1 communaute view tout > included .1 group collecte v1 cacti access collecte "" any noauth > exact tout none none syslocation Unknown (edit > /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure > /etc/snmp/snmp.local.conf) pass .1.3.6.1.4.1.4413.4.1 > /usr/bin/ucd5820stat > > > > Is it possible in my snmpd.conf source a solution as : > > com2sec nagios 192.168.1.1 communaute view tout > included .1 group collecte v1 cacti access collecte "" any noauth > exact tout none none syslocation Unknown (edit > /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure > /etc/snmp/snmp.local.conf) pass .1.3.6.1.4.1.4413.4.1 > /usr/bin/ucd5820stat *Exec **["disk-snmp"]* > > -- You received this message because you are subscribed to the > Google Groups "Puppet Users" group. To unsubscribe from this group > and stop receiving emails from it, send an email to > puppet-users+unsubscribe@googlegroups.com. To post to this group, > send email to puppet-users@googlegroups.com. Visit this group at > http://groups.google.com/group/puppet-users?hl=en. For more > options, visit https://groups.google.com/groups/opt_out. > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlGnk9QACgkQ5xgg9J6hpUuvZgCfUCe4ymWQW83x8YZOYdR8q7DA Va8AoIL+gF0uF0OXNsv8YDpKfyPDhmXL =z7Jy -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, May 30, 2013 12:32:05 PM UTC-5, Stan wrote:> > Hello > > Here is my manifest for snmpd, my problem now is that my manifest will run > every time because my snmpd.conf file changes after the "exec"!! I want > that my manifest run when the snmpd.conf (only snmpd.conf source and not > with exec) file change or when my /etc/fstab file on the client changeand > it restart the snmpd service. > > > I do not know if I''m very clear, but it is not easy to explain it in > English. > > Did you have an idea? >Your basic problem is that you are trying to manage the same physical resource (file /etc/snmpd/snmpd.conf) via two different Puppet resource declarations: a File and an Exec. Such an approach does not work with Puppet because Puppet checks each (puppet) resource individually to determine whether it needs to be applied. Additionally, Execs *always* run unless they have reason not to do, such as can be expressed via the ''refreshonly'', ''creates'', ''if'', or ''unless'' parameters. But those are not sufficient here, as I discuss next. In this case, when Puppet checks whether to apply File[/etc/snmpd/snmpd.conf], it always sees that the version present on the client does not match the one one the server. It therefore applies the version from server, then notifies the Exec. The Exec later modifies that same file (so that it again fails to match the version on the server). This will keep happening forever, because the File and Exec declarations effectively conflict with each other. The approach most in the Puppet paradigm would be to gather from the client, up front, all the information needed to determine the full contents of the target file, and then to apply the correct complete contents via a single File resource. To do that, replace your Exec with a custom fact that gathers the local filesystem information, and replace the flat ''source'' of File[''/etc/snmpd/snmpd.conf''] with ''content'' drawn from a template that supplies the variable part of the file based on the fact value. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.