Dear all, I have a module like this: class mom_priv_config{ file { ''config'': owner => ''root'', group => ''root'', mode => ''0644'', name => ''/var/torque/mom_priv/config'', content => template(''w_nodes/mom_priv-config.tpl''), #notify => Service[''pbs_mom''] } } which is working great by its own. But all I want is to carry on with this *ONLY IF* "/var/torque/mom_priv" directory exists on the client. If there is no such directory presents, just ignore. How can I do this? I looked in the net but nothing came out as a solution to me. Any one can help me with please? Cheers!! -- 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.
Peter Bukowinski
2011-Sep-28 15:33 UTC
Re: [Puppet Users] How to check if a given "directory" exists??
On Sep 28, 2011, at 9:37 AM, Sans wrote:> Dear all, > > I have a module like this: > > class mom_priv_config{ > file { > ''config'': > owner => ''root'', group => ''root'', mode => ''0644'', > name => ''/var/torque/mom_priv/config'', > content => template(''w_nodes/mom_priv-config.tpl''), > #notify => Service[''pbs_mom''] > } > } > > which is working great by its own. But all I want is to carry on with > this *ONLY IF* "/var/torque/mom_priv" directory exists on the client. > If there is no such directory presents, just ignore. How can I do > this? I looked in the net but nothing came out as a solution to me. > Any one can help me with please? Cheers!! > > -- > 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. >I''d create a custom fact that checks for the existence of the mom_priv directory -- something like this: # mom_priv_test.rb if FileTest.directory?("/var/torque/mom_priv") Facter.add("mom_priv_test") do setcode { true } end end # Now you can use this fact to wrap your file resource in an if statement: class mom_priv_config { if $mom_priv_test == ''true'' { file { ''/var/torque/mom_priv/config'': ensure => present, owner => ''root'', group => ''root'', mode => ''0644'', content => template(''w_nodes/mom_priv-config.tpl''), #notify => Service[''pbs_mom''], } } } -- Peter M. Bukowinski Sr. Systems Engineer Janelia Farm Research Campus, HHMI -- 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.
Sans
2011-Sep-28 22:38 UTC
[Puppet Users] Re: How to check if a given "directory" exists??
Thanks Peter! Custom fact is a great idea but the downside is one needs to create a custom-fact each for every check you wanna perform. Isn''t there anything a bit more dynamic, like checking the location on fly ( bash equivalent: if [ -d "/var/torque/mom_priv" ]; ) ?? Cheers!! On Sep 28, 4:33 pm, Peter Bukowinski <pmb...@gmail.com> wrote:> > I''d create a custom fact that checks for the existence of the mom_priv directory -- something like this: > > # mom_priv_test.rb > if FileTest.directory?("/var/torque/mom_priv") > Facter.add("mom_priv_test") do > setcode { true } > end > end > # > > Now you can use this fact to wrap your file resource in an if statement: > > class mom_priv_config { > if $mom_priv_test == ''true'' { > file { ''/var/torque/mom_priv/config'': > ensure => present, > owner => ''root'', > group => ''root'', > mode => ''0644'', > content => template(''w_nodes/mom_priv-config.tpl''), > #notify => Service[''pbs_mom''], > } > } > > } > > -- > Peter M. Bukowinski > Sr. Systems Engineer > Janelia Farm Research Campus, HHMI-- 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.
Dominik Zyla
2011-Sep-28 23:58 UTC
Re: [Puppet Users] Re: How to check if a given "directory" exists??
On 09/29/2011 12:38 AM, Sans wrote:> Thanks Peter! > Custom fact is a great idea but the downside is one needs to create a > custom-fact each for every check you wanna perform. Isn''t there > anything a bit more dynamic, like checking the location on fly ( bash > equivalent: if [ -d "/var/torque/mom_priv" ]; ) ?? Cheers!! > > > > > On Sep 28, 4:33 pm, Peter Bukowinski<pmb...@gmail.com> wrote: >> >> I''d create a custom fact that checks for the existence of the mom_priv directory -- something like this: >> >> # mom_priv_test.rb >> if FileTest.directory?("/var/torque/mom_priv") >> Facter.add("mom_priv_test") do >> setcode { true } >> end >> end >> # >> >> Now you can use this fact to wrap your file resource in an if statement: >> >> class mom_priv_config { >> if $mom_priv_test == ''true'' { >> file { ''/var/torque/mom_priv/config'': >> ensure => present, >> owner => ''root'', >> group => ''root'', >> mode => ''0644'', >> content => template(''w_nodes/mom_priv-config.tpl''), >> #notify => Service[''pbs_mom''], >> } >> } >> >> }Hello, You can work it around with something like: exec { ''mkdir -p 0644'': path => "/usr/bin:/usr/sbin:/bin", unless => "[ -d ''/var/torque/mom_priv'' ]" } Hope this helps. -- Dominik Zyla -- 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
2011-Sep-29 13:55 UTC
[Puppet Users] Re: How to check if a given "directory" exists??
On Sep 28, 5:38 pm, Sans <r.santanu....@gmail.com> wrote:> Thanks Peter! > Custom fact is a great idea but the downside is one needs to create a > custom-fact each for every check you wanna perform. Isn''t there > anything a bit more dynamic, like checking the location on fly ( bash > equivalent: if [ -d "/var/torque/mom_priv" ]; ) ?? Cheers!!The idea in the first place runs somewhat against the grain for Puppet: in general, you should prefer Puppet to tell, rather than to ask. Thus, the question is why Puppet doesn''t already know whether / var/torque/mom_priv should exist. By design, Puppet DSL has no direct mechanism for specifying client-side logic. That leaves you with three alternatives for configuring clients based on unmanaged state details: 1) Use custom facts to report client state details to the master, and perform the logic there. 2) Use an Exec to run a script, either as literal code or from a file. 3) Write a custom type and provider in Ruby that does what you want. Where possible, I recommend avoiding all of those and instead managing the state in question. 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.