Thank you for explanatory response.
I ended up using puppetdbquery
<https://github.com/dalen/puppet-puppetdbquery#query_resources> instead of
exported "resources", so I managed to avoid this ordering mess completely.
On Tuesday, January 9, 2018 at 3:05:33 AM UTC+2, Matthew Kennedy wrote:
>
>
>
> As far as I understand this is not really possible. This is because you
> don’t have control over the order of compilation of resources into the
> catalog. The compiler first evaluates all classes then moves on and
> eventually has a step that evaluates all collections and so on until the
> catalog is complete.
>
> You can work around this by ‘bumping scope’ which means you need to get the
> evaluation of the getparam() to happen after the collection has occurred and
> the resources are in the catalog. This is essentially what is happening in
> your define example.
>
> By bumping scope I mean that you need to do any evaluations in a define that
> is ‘one scope’ more then then where then resources will be added to the
> catalog. My scope I mean the order that the compiler will evaluate things.
>
> So when you have a collection in a class the actual collection will happen
> after all classes are evaluated by the initial pass by the compiler hence why
> you see the behavior you do. So if you create a define, use it in the class
> and have that define evaluate the getparam() then it /might/ work. Of course
> you won’t be able to get to those values in your class (because its already
> been evaluated). I say /might/ work because you can’t be sure that the define
> you create and the defined type you collected will happen in the right order
> ie that the collection will happen first. To be sure you can create a second
> define and use that in the first define and move the evaluation to the new
> second define. This is why I call this ‘bumping scope’. At this point the
> evaluation will happen after the collection’s defined types are in the
> catalog and getparam() will work. This get fun when defines make use of
> defines and the other defines need to reference these 2nd level (or 3rd
> level) defines. You can keep adding defines to get things to work.
>
> Now this looks ugly and is and I feel bad that I’ve done this but it works
> well and has predictable results.
>
> Finally the only way I think this can be fixed is it puppet went to a
> multipass compiler that would ‘reevaluate’ resources if evaluations
> occurred that reference those resources or their parameters. This would
> slow down performance quite and bit and have almost no benefit for most
> people.
>
> *From: *desertkun <javascript:>
> *Sent: *Monday, January 8, 2018 9:10 AM
> *To: *Puppet Users <javascript:>
> *Subject: *[Puppet Users] Puppet ordering: ensure exported resource to
> beevaluated BEFORE classes
>
>
>
> I would like to export "location" information from one node to another.
> And stuck with that problem for weeks now.
>
>
>
> In order to achieve that, I use exported resources. Here's the simplified
> idea:
>
>
>
> *define *location (*$host*) {
>
> notify {*"Location being defined **${title}** -> **${host}**"*: }
>
> }
>
>
>
> # export the location
>
> *node **'a' *{
>
> @@location { *"mysql-server"*:
>
> host => *$hostname*
>
> }
>
> }
>
>
>
> *node **'b' *{
>
> # later import it on another node
>
> Location <<| title == *"mysql-server" *|>>
>
> # extract the data
>
> * $mysql_server_host *= getparam(Location[*"mysql-server"*], *"host"*)
>
> }
>
>
>
> Pretty much I use exported resources as some sort of exported "facts". The
> problem with that, that puppet cannot realize the Location inside the
> classes or at node level scope, but does it just fine within resources:
>
>
>
> *DOES NOT WORK:*
>
>
>
> *class *class_example() {
>
> *# something like realize Location["mysql-server"] doesn't even compile*
>
> Location <<| title == *"mysql-server" *|>>
>
> *$mysql_server_host *= getparam(Location[*"mysql-server"*], *"host"*)
>
> notify {*"Example in class: **${mysql_server_host}**"*: }
>
> }
>
>
>
> *node **'b' *{
>
> *class *{ class_example: }
>
> }
>
>
>
> Yields: "Notice: Example in class:"
>
>
>
> *WORKS JUST FINE:*
>
>
>
> *define *resource_example() {
>
> Location <<| title == *"mysql-server" *|>>
>
> *$mysql_server_host *= getparam(Location[*"mysql-server"*], *"host"*)
>
> notify {*"Example in resource: **${mysql_server_host}**"*: }
>
> }
>
>
>
> Yields "Notice: Example in resource: hostname-x"
>
>
>
> The problem with that, I my guess, the puppet evaluates stuff in two
> stages, classes first, and then resources, including exported resources.
> What is also interesting, that notify I've put for debug yields like that:
>
>
>
> Example in class:
>
> Example in resource: hostname-x
>
> Location being defined mysql-server -> hostname-x
>
>
>
> If I do "require => Location[*"mysql-server"*]" for the resource, the
> ordering shows right, but result is the same:
>
>
> Example in class:
>
> Location being defined mysql-server -> hostname-x
>
> Example in resource: hostname-x
>
>
>
> The question is, how do I enforce puppet to evaluate class AFTER exported
> resource? Would "stages" help me out here? As a workaround, I have to wrap
> classes in a single-instance resources.
>
>
>
> Thank you very much in advance.
>
> --
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/e331a5fc-657a-47ae-aa0d-64f2a655ff10%40googlegroups.com
>
> <https://groups.google.com/d/msgid/puppet-users/e331a5fc-657a-47ae-aa0d-64f2a655ff10%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/19e0c9a6-fa17-444a-a01b-da4941df069a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.