On Monday, April 4, 2016 at 7:24:50 AM UTC-5, Johan De Wit wrote:
>
> Hi, 
>
> Seems it is not possible, well, I cannot make it work.
>
> Depending on some class parameter, some exported resources should be 
> collected or not.
>
> eg. 
>
>
> class X (
>   $collect_tags = ['cond1', 'cond2']
> ) {
>
> $my_cond = my_magic_function($collect_tags)  # returns the string "tag == 
> 'cond1' or tag=='cond2'"
>
> My_exp_res <<| $my_cond |>>
> }
>
> But the only result I get :  Error 400 on SERVER: Syntax error at '|>>'; 
> expected '}'
>
>

I can't say I'm a bit surprised.  Shell script is the only language I can 
think of where something like that can work.  Puppet parses the manifest, 
*then* evaluates the result; replacing variable references with the 
corresponding values is an aspect of evaluation.  To put it another way, a 
Puppet variable reference can represent only a value, not DSL code.

 

>
> Whatever i tried, nothing gave me the desired result.  Using single quotes, 
> double quotes, escaping quotes ....
>
> And <<| tag == $collect_tags |>> ( <<| tag == ['cond1','cond2'] |>> does not 
> give me the desired result, only one exported resource is collected.  But I 
> try to ovoid this, because the behavior of this i unpredictable, as 
> documented in the docs.
>
>

In fact, according to the docs, the behavior is *undefined* in the Puppet 
3.7 and 3.8 series (and in Puppet 4, which you did not mention).  I 
generally take that as an even more forboding characteristic than 
"unpredictable".  Calling the behavior "undefined" should be interpreted as 
meaning "don't do that".

 

>
> I already I'm a big fan of iteration, but this needs to work on puppet 
> 3.[7|8].x
>
> For now I will change my parameter to a single string and us an if clause 
> like ...
>
> if  ( $collect_tag =~ /all$/ ) {
>   My_exp_res <<|   |>>
> } else {
>   My_exp_res <<| tag == $collect_tag >>
> }
>
>

Is enabling the future parser a viable alternative for you?  That would 
allow you to use the new-style iteration functions even in v3.[78].

 

> I will loose the ability to collect on multiple nodes this way, but we can 
> live with this for the moment.
>
> Peeking to puppetdbquery as an alternative ....
>
>

I'm not quite seeing how puppetdbquery would help, but Felix's suggestion 
to build a solution in the old-school way, based on array-titled resource 
declarations, should work in any version of Puppet from at least 0.24 
through 4.4.


John

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/e8844fcc-c9cb-4dc7-a495-e39f201eb2e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to