Ask Your Question

Interpolate Variable in Resource

asked 2014-09-15 13:36:06 -0600

Derongan gravatar image

updated 2014-09-17 11:40:00 -0600

I have a class that has a resource. This resource generates a variable. The parent class must pass in a string containing this variable, but has no access to the variable. Is there any way to pass the string in as a string, and then have the resource perform the string interpolation?

Relevant code:

class my_program
    { "Name":
        install_options=>[ "config_file=${install_options}/file.ini"],
        files_to_grab => ['setup','file.ini'],

define special_package(install_options)
    $working_directory = create_temporary()    #create_temporary creates a directory in
                                               #the temp folder and returns its name.

    #Code here would grab the needed files and drops them in working directory

    package { $title:
        ensure => installed,
        source => "${working_directory}/setup",
        install_options => $install_options,  #In this specific case, install_options needs 
    }                                         #to reference the temporary directory. However
                                              #it is interpolated in the scope of my_program
                                              #and resolves to "config_file=/file.ini"
                                              #instead of "config_file=<TEMPDIR>/file.ini"
edit retag flag offensive close merge delete



Paste some code or no one can help you.

lavaman gravatar imagelavaman ( 2014-09-15 14:15:45 -0600 )edit

Added an example.

Derongan gravatar imageDerongan ( 2014-09-15 15:41:31 -0600 )edit

This example code is confusing, try making it a case of what you're actually trying to accomplish. However with what you have posted, I'm nearly certain the answer is no.

ramindk gravatar imageramindk ( 2014-09-16 15:38:28 -0600 )edit

I added more below the code. Hopefully I explained myself better there.

Derongan gravatar imageDerongan ( 2014-09-16 16:19:06 -0600 )edit

What are you trying achive? Don't really know what's the use case but you can use facter to get parameter from configuration file. I reckon you are doing something really top secret because this question is more a riddle ;)

3h4x gravatar image3h4x ( 2014-09-17 05:00:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-10 12:56:53 -0600

binford2k gravatar image

This code does not do what you think it does.

  $working_directory = create_temporary()    #create_temporary creates a directory in
                                             #the temp folder and returns its name.

Since the catalog is compiled on the master, and functions are run during compilation, this function will create a temp directory on the master, but act as though it exists on the agent too.

By the description you gave and the code, it sounds like you're trying to interpolate a variable into itself, which doesn't make sense. You'll need to refactor your code for clarity before trying to get clever with it.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-09-15 13:36:06 -0600

Seen: 653 times

Last updated: Aug 10