Issue #19315 has been updated by James Shubin.

You do have some interesting points. Hopefully I'll be able to address them 
adequately:

I guess the reason why I think it makes sense is that I see $name as a 
variable, and logically it makes sense to allow any first class type. (Why 
should a string be special?)

In practical terms, the $name is the unique identifier of the object; for a 
list:
<pre>
$thing = [
        {'keya' => 'value1', 'keyb' => 'value1'},
        {'keya' => 'value2', 'keyb' => 'value2'}
]
</pre>
that exists as input for a list of objects, using the hash is the only way to 
guarantee uniqueness.
I used to use the hash as the $name, but as mentioned in this bug report, I've 
had some bugs pop up. My workaround has been to "hash the hash" to create a new 
unique name:

<pre>
$newname = split(inline_template('<%= thing.map{|x| x.is_a?(Hash) ? 
(x["keya"].to_s + "-" + x["keyb"].to_s) : x}.join("#") %>'), '#')
</pre>

... and then inside the define, I split apart the values I wanted from the 
dashes, and use them. There's no other way to use an array of hashes, as input 
to a define, and be able to pass the hash into the define too, unless puppet 
invents some new constructs that you've alluded to.

Anyways, hopefully we can fix the 'pson' bug I'm seeing. It doesn't make sense 
that it only breaks when run through the puppetmaster, since the code itself 
obviously works fine when run in standalone mode. Let's let it keep working 
until we have something better in place.


----------------------------------------
Bug #19315: puppet is buggy when using a hash as a $name
https://projects.puppetlabs.com/issues/19315#change-83705

Author: James Shubin
Status: Unreviewed
Priority: Normal
Assignee: 
Category: 
Target version: 
Affected Puppet version: 
Keywords: 
Branch: 


<pre>

It turns out if you're doing some fancy puppet work, it is sometimes useful to 
use a hash as a $name var.
In my particular case, I'm actually passing an array of hashes to a define 
(which ultimately causes the define to be called once for each hash).
This actually works perfectly when run locally with puppet apply, however when 
running with puppet agent --test, it sometimes works and sometimes fails with:

Error: Could not retrieve catalog from remote server: Could not intern from 
pson: Could not convert from pson: Could not find relationship source 
"Foo::Bar::My_define[sourcedmzaddress192.168.101.200]"

The hash I used was:
{'source' => 'dmz', 'address' => '192.168.101.200'}

A few comments:
1. It's strange that the execution is not deterministic. Why does it sometimes 
work and sometimes not?
2. It's odd that it *always* works locally, but not always when through the 
puppet master.
3. The error message is confusing, not sure what it is trying to tell me.

Thanks,
James
</pre>



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to