Accessing resource attributes

46 views
Skip to first unread message

R.I.Pienaar

unread,
Jul 31, 2015, 6:35:45 AM7/31/15
to puppet-dev
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?

---
R.I.Pienaar

Henrik Lindberg

unread,
Jul 31, 2015, 9:10:09 AM7/31/15
to puppe...@googlegroups.com
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/

R.I.Pienaar

unread,
Jul 31, 2015, 9:14:24 AM7/31/15
to puppet-dev
this one wasn't obvious to me :) I did not realize its lazy evaluated
so that explains it

thanks
Reply all
Reply to author
Forward
0 new messages