I would like to check for the existence of a template file and if that template exists, use it otherwise move on. The file would obviously need to exist on the Puppet server, not the client. Here is my code. $filetest =>> File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/$hostname.erb") >> > > >> if $filetest == "true" { > > >> file { ''/etc/samba/smb.conf'': > > notify => Service["smb", "winbind"], > > replace => ''no'', > > path => ''/etc/samba/smb.conf'', > > ensure => file, > > content => template("samba/smb.erb", >> "samba/${hostname}.erb"), > > require => Package["samba"], > > } > > } else { > > >> file { ''/etc/samba/smb.conf'': > > notify => Service["smb", "winbind"], > > replace => ''no'', > > path => ''/etc/samba/smb.conf'', > > ensure => file, > > content => template("samba/smb.erb"), > > require => Package["samba"], > > } > > } > > >I keep getting the error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at ''.''; expected ''}'' at /etc/puppetlabs/puppet/modules/samba/manifests/init.pp:34 on node when I run the following test, it seems to work fine, but if I modify my code above within puppet to use this, it fails also... # cat test.rb> $test = > File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/file.erb") > print $test > # ruby test.rb > trueAny ideas? A million thanks in advance Ted -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Ashley Penney
2013-Aug-07 20:47 UTC
Re: [Puppet Users] Checking for the existence of a file
You cannot use ruby code in Puppet directly, which is why this isn''t working for you. To do this you would need to write a "Puppet Function" as documented at http://docs.puppetlabs.com/guides/custom_functions.html. This would then let you do something like: if exists(''/file'') { Functions always run on the master, not the agent, so this would then test for the file on the master. On Wed, Aug 7, 2013 at 1:20 PM, Ted Fiedler <fiedlert@gmail.com> wrote:> I would like to check for the existence of a template file and if that > template exists, use it otherwise move on. The file would obviously need to > exist on the Puppet server, not the client. Here is my code. > > $filetest >>> File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/$hostname.erb") >>> >> >> >>> if $filetest == "true" { >> >> >>> file { ''/etc/samba/smb.conf'': >> >> notify => Service["smb", "winbind"], >> >> replace => ''no'', >> >> path => ''/etc/samba/smb.conf'', >> >> ensure => file, >> >> content => template("samba/smb.erb", >>> "samba/${hostname}.erb"), >> >> require => Package["samba"], >> >> } >> >> } else { >> >> >>> file { ''/etc/samba/smb.conf'': >> >> notify => Service["smb", "winbind"], >> >> replace => ''no'', >> >> path => ''/etc/samba/smb.conf'', >> >> ensure => file, >> >> content => template("samba/smb.erb"), >> >> require => Package["samba"], >> >> } >> >> } >> >> >> > I keep getting the error: > > err: Could not retrieve catalog from remote server: Error 400 on SERVER: > Syntax error at ''.''; expected ''}'' at > /etc/puppetlabs/puppet/modules/samba/manifests/init.pp:34 on node > > > when I run the following test, it seems to work fine, but if I modify my > code above within puppet to use this, it fails also... > > # cat test.rb >> $test >> File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/file.erb") >> print $test >> # ruby test.rb >> true > > > Any ideas? > > A million thanks in advance > > Ted > > -- > 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. > 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+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. For more options, visit https://groups.google.com/groups/opt_out.
Rilindo Foster
2013-Aug-07 21:01 UTC
Re: [Puppet Users] Checking for the existence of a file
This line here:> content => template("samba/smb.erb", "samba/${hostname}.erb"),What is your intention with having multiple .erb files per hostname? That might help us figure if there a different solution is warranted. -Rilindo On Aug 7, 2013, at 3:20 PM, Ted Fiedler <fiedlert@gmail.com> wrote:> I would like to check for the existence of a template file and if that template exists, use it otherwise move on. The file would obviously need to exist on the Puppet server, not the client. Here is my code. > > $filetest = File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/$hostname.erb") > > if $filetest == "true" { > > file { ''/etc/samba/smb.conf'': > notify => Service["smb", "winbind"], > replace => ''no'', > path => ''/etc/samba/smb.conf'', > ensure => file, > content => template("samba/smb.erb", "samba/${hostname}.erb"), > require => Package["samba"], > } > } else { > > file { ''/etc/samba/smb.conf'': > notify => Service["smb", "winbind"], > replace => ''no'', > path => ''/etc/samba/smb.conf'', > ensure => file, > content => template("samba/smb.erb"), > require => Package["samba"], > } > } > > > I keep getting the error: > > err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at ''.''; expected ''}'' at /etc/puppetlabs/puppet/modules/samba/manifests/init.pp:34 on node > > > when I run the following test, it seems to work fine, but if I modify my code above within puppet to use this, it fails also... > > # cat test.rb > $test = File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/file.erb") > print $test > # ruby test.rb > true > > Any ideas? > > A million thanks in advance > > Ted > > -- > 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. > 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+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. For more options, visit https://groups.google.com/groups/opt_out.
I have a base Samba config and then about 50 server specific samba shares. So I apply a base config to all the servers, then if that server has extra shares that are not in the base, it is included. On Wednesday, August 7, 2013 5:01:19 PM UTC-4, RIlindo Foster wrote:> > This line here: > > > content => template("samba/smb.erb", "samba/${hostname}.erb"), > > What is your intention with having multiple .erb files per hostname? That > might help us figure if there a different solution is warranted. > > -Rilindo > > On Aug 7, 2013, at 3:20 PM, Ted Fiedler <fied...@gmail.com <javascript:>> > wrote: > > I would like to check for the existence of a template file and if that > template exists, use it otherwise move on. The file would obviously need to > exist on the Puppet server, not the client. Here is my code. > > $filetest = >>> File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/$hostname.erb") >>> >> >> >>> if $filetest == "true" { >> >> >>> file { ''/etc/samba/smb.conf'': >> >> notify => Service["smb", "winbind"], >> >> replace => ''no'', >> >> path => ''/etc/samba/smb.conf'', >> >> ensure => file, >> >> content => template("samba/smb.erb", >>> "samba/${hostname}.erb"), >> >> require => Package["samba"], >> >> } >> >> } else { >> >> >>> file { ''/etc/samba/smb.conf'': >> >> notify => Service["smb", "winbind"], >> >> replace => ''no'', >> >> path => ''/etc/samba/smb.conf'', >> >> ensure => file, >> >> content => template("samba/smb.erb"), >> >> require => Package["samba"], >> >> } >> >> } >> >> >> > I keep getting the error: > > err: Could not retrieve catalog from remote server: Error 400 on SERVER: > Syntax error at ''.''; expected ''}'' at > /etc/puppetlabs/puppet/modules/samba/manifests/init.pp:34 on node > > > when I run the following test, it seems to work fine, but if I modify my > code above within puppet to use this, it fails also... > > # cat test.rb >> $test = >> File.exists?("/etc/puppetlabs/puppet/modules/samba/templates/file.erb") >> print $test >> # ruby test.rb >> true > > > Any ideas? > > A million thanks in advance > > Ted > > -- > 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...@googlegroups.com <javascript:>. > To post to this group, send email to puppet...@googlegroups.com<javascript:> > . > Visit this group at http://groups.google.com/group/puppet-users. > 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+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. For more options, visit https://groups.google.com/groups/opt_out.