Search code examples
rubypuppet

puppet stdlib 'member" function not working


Trying to use the member function of the puppet stdlib module:

effectively:

$myvariable = 'FOO'

then when using the member function:

member(['FOO','BAR'], $myvariable)

I keep getting the error message:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Function 'member' must be the value of a statement at /etc/puppet/modules/mymodule/manifests/init.pp:###  

Solution

  • Looking at the stdlib documentation for member, we see that member is an rvalue. This means in this context that you need to have its output assigned. This is what the error message of must be the value of a statement is hinting at. Note a helpful wikipedia article on l-values and r-values https://en.wikipedia.org/wiki/Value_(computer_science)#lrvalue.

    Your code will work, for example, if you assign the output of member(['FOO','BAR'], $myvariable) to a variable or a resource attribute.

    For example:

    $myvariable = 'FOO'
    $variable = member(['FOO','BAR'], $myvariable)
    notify { $variable: }
    

    will result in a notify 'true' during compilation.