Puppet: System Administration Automated

Support

Ticket #1012: puppet-use-template-if-found.patch

File puppet-use-template-if-found.patch, 1.9 kB (added by adamhjk, 10 months ago)

Puppet should prefer local templates over module templates

  • a/lib/puppet/module.rb

    old new  
    6363            return template 
    6464        end 
    6565 
     66        # If we can find the template in :templatedir, we return that. 
     67        td_file = File.join(Puppet.settings.value(:templatedir, environment), template) 
     68        return td_file if File.exists?(td_file) 
     69           
    6670        path, file = split_path(template) 
    6771 
    6872        # Because templates don't have an assumed template name, like manifests do, 
     
    7680        if mod 
    7781            return mod.template(file) 
    7882        else 
    79             return File.join(Puppet.settings.value(:templatedir, environment), template) 
     83            return td_file # Return this anyway, since we're going to fail. 
    8084        end 
    8185    end 
    8286 
  • a/spec/unit/other/modules.rb

    old new  
    8080        File.stubs(:directory?).returns(true) 
    8181        Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate" 
    8282    end 
     83     
     84    it "should return the file in the templatedir if it exists" do 
     85        Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates") 
     86        Puppet[:modulepath] = "/one:/two" 
     87        File.stubs(:directory?).returns(true) 
     88        File.stubs(:exists?).returns(true) 
     89        Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate" 
     90    end 
    8391 
    8492    it "should use the main templatedir if no module is found" do 
    8593        Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates")