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 <[email protected]> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to