Re: [Puppet Users] How to apply template based on a string in a file
Hi, I think that the problem here is a big misunderstood about how puppet works. Puppet DSL is a declarative language, you do not have to tell what to do (grep "xxx" on file "yyy"), you have to tell which final state do you want. Obviously this final state may depend on data (facts/hiera) but never on an action (grep) Moreover, puppet manifests are compiled in the puppetmaster (so if it would be possible to do a grep or any other action, it would be made on the master). The problem you are facing is that the code if "any string that you may want" is always true (at least the string is empty) that's why always falls in the first condition. regards, On Fri, Feb 14, 2014 at 12:18 AM, Ray wrote: > Newbie question: > I need to be able to apply a specific template based on whether a string > is found in an > existing file on the client or not. I tried the following (found an > example somewhere... it does not work.. always falls into the first > condition) > > What would be the correct way to check for the value in the file? > > > if "grep STANDARD /var/adm/buildIT/ServerBuild.dat 2>/dev/null" > { > file { '/etc/openssh/sshd_config': > ensure => file, > backup => false, > content => template("sshdconfig/sshdconfigsol.erb"), > notify => Service['ssh'] > } > > service { 'ssh': > ensure => running, > enable => true, > hasstatus => true, > hasrestart => true, > } > } > else > { > file { '/etc/openssh/sshd_config': > ensure => file, > backup => false, > content => template("sshdconfig/sshdconfigsolpm.erb"), > notify => Service['ssh'] > } > > service { 'ssh': > ensure => running, > enable => true, > hasstatus => true, > hasrestart => true, > } > } > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/e502a7ac-cebc-4454-900e-d504f2a89956%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > -- José Luis Ledesma -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAF_B3dcQ1AzcKCY3Qb0zA-26uL1tkTEs0z1PMNLZT5A3Nen-xA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Puppet Users] How to apply template based on a string in a file
Or place those values in hiera. > On 15 Feb 2014, at 0:12, Johan De Wit wrote: > > If you need information from the client, then you should think 'facter'. > > Or you could write a custom fact, or use external facts. > > http://puppetlabs.com/blog/facter-1-7-introduces-external-facts > http://docs.puppetlabs.com/guides/custom_facts.html > > HTH > > Jo > > >> On 02/14/2014 12:18 AM, Ray wrote: >> Newbie question: >> I need to be able to apply a specific template based on whether a string is >> found in an >> existing file on the client or not. I tried the following (found an example >> somewhere... it does not work.. always falls into the first condition) >> >> What would be the correct way to check for the value in the file? >> >> >> if "grep STANDARD /var/adm/buildIT/ServerBuild.dat 2>/dev/null" >> { >> file { '/etc/openssh/sshd_config': >> ensure => file, >> backup => false, >> content => template("sshdconfig/sshdconfigsol.erb"), >> notify => Service['ssh'] >> } >> >> service { 'ssh': >> ensure => running, >> enable => true, >> hasstatus => true, >> hasrestart => true, >> } >> } >> else >> { >> file { '/etc/openssh/sshd_config': >> ensure => file, >> backup => false, >> content => template("sshdconfig/sshdconfigsolpm.erb"), >> notify => Service['ssh'] >> } >> >> service { 'ssh': >> ensure => running, >> enable => true, >> hasstatus => true, >> hasrestart => true, >> } >> } >> >> -- >> 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+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/puppet-users/e502a7ac-cebc-4454-900e-d504f2a89956%40googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. > > > -- > Johan De Wit > > Open Source Consultant > > Red Hat Certified Engineer (805008667232363) > Puppet Certified Professional 2013 (PCP006) > _ > > Open-Future Phone +32 (0)2/255 70 70 > Zavelstraat 72 Fax +32 (0)2/255 70 71 > 3071 KORTENBERG Mobile+32 (0)474/42 40 73 > BELGIUM http://www.open-future.be > _ > > > Upcoming Events: > > Zabbix Certified Training | > http://www.open-future.be/zabbix-certified-training-10-till-12th-march > > Zabbix for Large Environments Training | > http://www.open-future.be/zabbix-large-environments-training-13-till-14th-march > > Puppet Introduction Course | > http://www.open-future.be/puppet-introduction-course-14th-april > > Puppet Advanced Training | > http://www.open-future.be/puppet-advanced-training-15-till-17th-april > > Subscribe to our newsletter: http://eepurl.com/BUG8H > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/52FE164C.6070803%40open-future.be. > For more options, visit https://groups.google.com/groups/opt_out. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/F87542EC-CD35-47BB-8F01-98262D79E463%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Puppet Users] How to apply template based on a string in a file
If you need information from the client, then you should think 'facter'. Or you could write a custom fact, or use external facts. http://puppetlabs.com/blog/facter-1-7-introduces-external-facts http://docs.puppetlabs.com/guides/custom_facts.html HTH Jo On 02/14/2014 12:18 AM, Ray wrote: Newbie question: I need to be able to apply a specific template based on whether a string is found in an existing file on the client or not. I tried the following (found an example somewhere... it does not work.. always falls into the first condition) What would be the correct way to check for the value in the file? if "grep STANDARD /var/adm/buildIT/ServerBuild.dat 2>/dev/null" { file { '/etc/openssh/sshd_config': ensure => file, backup => false, content => template("sshdconfig/sshdconfigsol.erb"), notify => Service['ssh'] } service { 'ssh': ensure => running, enable => true, hasstatus => true, hasrestart => true, } } else { file { '/etc/openssh/sshd_config': ensure => file, backup => false, content => template("sshdconfig/sshdconfigsolpm.erb"), notify => Service['ssh'] } service { 'ssh': ensure => running, enable => true, hasstatus => true, hasrestart => true, } } -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e502a7ac-cebc-4454-900e-d504f2a89956%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Johan De Wit Open Source Consultant Red Hat Certified Engineer (805008667232363) Puppet Certified Professional 2013 (PCP006) _ Open-Future Phone +32 (0)2/255 70 70 Zavelstraat 72 Fax +32 (0)2/255 70 71 3071 KORTENBERG Mobile+32 (0)474/42 40 73 BELGIUM http://www.open-future.be _ Next Events: Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-march Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-march Puppet Intruction Course | http://www.open-future.be/puppet-introduction-course-14th-april Puppet Advanced Training | http://www.open-future.be/puppet-advanced-training-15-till-17th-april Subscribe to our newsletter | http://eepurl.com/BUG8H -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/52FE164C.6070803%40open-future.be. For more options, visit https://groups.google.com/groups/opt_out.
[Puppet Users] How to apply template based on a string in a file
Newbie question: I need to be able to apply a specific template based on whether a string is found in an existing file on the client or not. I tried the following (found an example somewhere... it does not work.. always falls into the first condition) What would be the correct way to check for the value in the file? if "grep STANDARD /var/adm/buildIT/ServerBuild.dat 2>/dev/null" { file { '/etc/openssh/sshd_config': ensure => file, backup => false, content => template("sshdconfig/sshdconfigsol.erb"), notify => Service['ssh'] } service { 'ssh': ensure => running, enable => true, hasstatus => true, hasrestart => true, } } else { file { '/etc/openssh/sshd_config': ensure => file, backup => false, content => template("sshdconfig/sshdconfigsolpm.erb"), notify => Service['ssh'] } service { 'ssh': ensure => running, enable => true, hasstatus => true, hasrestart => true, } } -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e502a7ac-cebc-4454-900e-d504f2a89956%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.