Jira (PUP-1214) File resources: Make source/content parameters and the file/template functions consistent.

10 views
Skip to first unread message

Nicholas Fagerlund (JIRA)

unread,
May 15, 2017, 2:42:08 PM5/15/17
to puppe...@googlegroups.com
Nicholas Fagerlund commented on New Feature PUP-1214
 
Re: File resources: Make source/content parameters and the file/template functions consistent.

We believe this issue has already been addressed in a later release of Puppet — in particular, we've updated the file function to work the same as the template function, so the really annoying gap should be dealt with.

If you experience this issue against the current version of Puppet, please add a comment to this ticket with your reproduction scenario.

For more info on getting the current version of Puppet Agent, see https://docs.puppet.com/puppet/latest/install_pre.html.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Nicholas Fagerlund (JIRA)

unread,
May 15, 2017, 2:43:08 PM5/15/17
to puppe...@googlegroups.com

Moses Mendoza (JIRA)

unread,
May 18, 2017, 1:56:26 PM5/18/17
to puppe...@googlegroups.com

Rob Reus (JIRA)

unread,
Oct 30, 2018, 10:27:08 AM10/30/18
to puppe...@googlegroups.com
Rob Reus commented on New Feature PUP-1214
 
Re: File resources: Make source/content parameters and the file/template functions consistent.

Nicholas Fagerlund this is incorrect. Both functions (file() and template()) have not been changed according to git history.

The original idea is to have the template() function also accept an array like the source parameter does. The first existing file in the array would then be used as template file. Right now, concatenation of multiple templates into one by providing multiple template files separated by commas still work. The proposed change has not been applied.

Example:

module dir

.
└── test
    ├── files
    │   ├── foobar
    │   └── foobaz
    ├── manifests
    │   └── init.pp
    └── templates
        ├── foobar.erb
        └── foobaz.erb

init.pp

class test {
  file { '/tmp/woking_template':
    ensure  => file,
    content => template('test/foobar.erb', 'test/foobaz.erb');
  }
 
  file { '/tmp/not_working_template':
    ensure  => file,
    content => template(["test/barfoo.erb", "test/foobar.erb"]);
 
  }
 
  file { '/tmp/working_file':
    ensure => file,
    source => ["puppet:///modules/test/barfoo", "puppet:///modules/test/foobar"];
  }
} 

Result:

/tmp/woking_template:
concatenated output of foobar.erb and foobaz.erb

/tmp/not_working_template
Error: Evaluation Error: Error while evaluating a Function Call, undefined method `split' for ["test/foobar.erb", "test/barfoo.erb"]:Array (file: /home/rob/puppet/test/manifests/init.pp, line: 9, column: 16) on node rreus.localdomain

/tmp/working_file:
content of modules/test/foobar as modules/test/barfoo does not exist

Expected result:

Contents of '/tmp/not_working_template' should be whatever is in test/templates/foobar.erb since test/templates/barfoo.erb does not exist. This works for the source parameter but not for the template() function.

 

Can someone look into this again? If it is feasible, we can include the function originally created by R.I.Pienaar and made into a module by Dean Wilson into upstream, or merge the multitemplate and template functions together. I do not see a use-case for concatenation of multiple template files into one so would gladly see that one make place for the proposed change. 

This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Oct 30, 2018, 12:59:04 PM10/30/18
to puppe...@googlegroups.com

I would much rather see a separate function that returns the first existing file/template given a list of paths. Such a function can then also accept different suffixes and this function can then be used with all kinds of functions taking a path (for example epp()). There is a find_file function in puppet core, but no find_template.

Rob Reus (JIRA)

unread,
Nov 1, 2018, 5:38:03 AM11/1/18
to puppe...@googlegroups.com
Rob Reus commented on New Feature PUP-1214

Henrik Lindberg taken backwards compatibility into account, that seems like the feasible solution to me. Having a find_template function will solve the above mentioned issue.

Henrik Lindberg (JIRA)

unread,
Nov 1, 2018, 6:35:07 AM11/1/18
to puppe...@googlegroups.com

Should not be too hard to implement a `find_template` function, but may be somewhat more complex since it needs to find both .erb and .epp templates.
Suggest taking `find_file` as a model, and then adapting the logic found in the EppEvaluator to do the search:

    unless Puppet::FileSystem.exist?(file)
      unless file =~ /\.epp$/
        file = file + ".epp"
      end
    end
 
    scope.debug "Retrieving epp template #{file}"
    template_file = Puppet::Parser::Files.find_template(file, env_name)
    if template_file.nil? ||  !Puppet::FileSystem.exist?(template_file)
      raise Puppet::ParseError, _("Could not find template '%{file}'") % { file: file }
    end

Jorie Tappa (JIRA)

unread,
Nov 19, 2018, 5:08:05 PM11/19/18
to puppe...@googlegroups.com

Jorie Tappa (JIRA)

unread,
Nov 19, 2018, 5:08:05 PM11/19/18
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jun 21, 2021, 2:33:02 PM6/21/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Team: Froyo Coremunity
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Jun 21, 2021, 2:33:03 PM6/21/21
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-1214
 
Re: File resources: Make source/content parameters and the file/template functions consistent.

I think I have this nearly implemented in a branch somewhere. Given the number of watchers and voter on this ticket, I'm going to reopen.

Josh Cooper (Jira)

unread,
Dec 10, 2021, 2:45:02 AM12/10/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Labels: redmine tbd
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages