On Wed, Sep 18, 2013 at 09:52:27AM -0700, Corey Osman wrote:
> Hi,
> 
> How can I verify the template exists in the given path?  Example,
> 
> Given the following in my manifest:
> 
> if $somevar == 'true' {
>       $templatefile='mymodule/mytemplate.xml.erb'
> }
> else {
>       $templatefile='mymodule/mytemplate2.xml.erb'
> }
> file{"somefile.txt":
>       ensure => present,
>       content => template($templatefile)
> }
> 

I'm not sure how this would fit into rspec, but in my manifests I use a function
to verify templates.  Perhaps pieces of this could be adapted for your purpose.

$ cat is_template.rb
#
# adapted from has_template from https://github.com/windowsrefund/puppet-tools
#
Puppet::Parser::Functions::newfunction(
  :is_template,
  :type => :rvalue,
  :doc => "Returns true if argument translates to a valid template.") do |args|

  require 'rubygems'
  require 'puppet'

  if value = 
Puppet::Parser::Files.find_template(args[0],lookupvar('environment'))
    return FileTest.exist?(value)
  end

  nil

end



> 
> How can I test that the template file exists in the given module path?
> 
> File.exists?("../../../#{templatefile}").should be_true ???
> 
> Additionally can I test if the variable $templatefile or $somevar is correct 
> and my logic is sane.  Is there a way to retrieve the manifest variables 
> within spec tests?
> 
> example:
> 
>       $somevar.should eq('true') ???
> 
> 
> 
> Corey
> 
> 
> -- 
> 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.

-- 

-ashley

If a new user has a bad time, IT'S A BUG!

-- 
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