On 2015-31-07 12:35, R.I.Pienaar wrote:
I just noticed last night we can now access resource and class attributes:
define x($y) {
}
x{"foo": y => "bar"}
notice(X["foo"]["y"])
this works, yay with the obvious parsing order caveats.
This works too:
define x($y) {
notify{$name: message => $y }
}
class one {
x{"one": y => "hello from one"}
}
include one
notice(X["one"]["y"])
but this does not:
define x($y) {
notify{$name: message => $y }
}
x{"hello": y => "hello world"}
notify{"outside": message => "hello from outside"}
notify{X["hello"]["y"]: }
notify{Notify["outside"]["message"]: } # works
notify{Notify["hello"]["message"]: } # fails
It can't find the notify inside the defined type X:
Error: Evaluation Error: Resource not found: Notify['hello']
commenting out the problem notify I do see:
Notice: /Stage[main]/Main/X[hello]/Notify[hello]/message: defined 'message' as
'hello world'
which suggests I didn't mess up the resource name
Is this a bug or just not supposed to work?
You said it yourself "the obvious parsing order caveats". Afaict, the
problem is that the resource has not yet been evaluated in the cases
where it did not work for you.
if you do something like
define foo { something { title: x => 1} }
foo { bar: }
notice Something['title']['x']
That fails because the evaluation of foo is lazy. When it is evaluated
it enqueues the evaluation of the 'something' and returns. Then an
attempt is made to access 'Something[title]' which will fail as it is
not yet evaluated. If you stick the second in a define, it will work as
it will be enqueued after what was enqueued in 'foo'.
e.g.
define foo { something { title: x => 1} }
define helper { notice Something['title']['x'] }
foo {bar: }
helper { yay: }
More about "the order of evaluation" can be read here:
http://puppet-on-the-edge.blogspot.se/2014/04/getting-your-puppet-ducks-in-row.html
- henrik
---
R.I.Pienaar
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/55BB73AD.60700%40cloudsmith.com.
For more options, visit https://groups.google.com/d/optout.