Jira (PUP-9186) Deferred doesn't work in 'notify' resource

3 views
Skip to first unread message

Michael Smith (JIRA)

unread,
Sep 27, 2018, 6:34:04 PM9/27/18
to puppe...@googlegroups.com
Michael Smith created an issue
 
Puppet / Bug PUP-9186
Deferred doesn't work in 'notify' resource
Issue Type: Bug Bug
Affects Versions: PUP 6.0.0
Assignee: Unassigned
Created: 2018/09/27 3:33 PM
Priority: Normal Normal
Reporter: Michael Smith

When running puppet apply (haven't checked when a server is involved) and using Deferred in a notify resource, the notify prints out the type's representation rather than the result of running the function. See https://gist.github.com/MikaelSmith/024807c1fdb1296a7118a559059d0c6d for a simple repro case.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Michael Smith (JIRA)

unread,
Sep 27, 2018, 6:35:04 PM9/27/18
to puppe...@googlegroups.com
Michael Smith assigned an issue to Henrik Lindberg
Change By: Michael Smith
Assignee: Henrik Lindberg

Michael Smith (JIRA)

unread,
Sep 27, 2018, 6:50:04 PM9/27/18
to puppe...@googlegroups.com
Michael Smith commented on Bug PUP-9186
 
Re: Deferred doesn't work in 'notify' resource

This is slightly confusing but probably user error. Resource names are resolved at compile time, and I was trying to use a Deferred type in my resource name (bad habits with notify).

Michael Smith (JIRA)

unread,
Sep 27, 2018, 6:50:05 PM9/27/18
to puppe...@googlegroups.com
Michael Smith commented on Bug PUP-9186

Probably a thing we should call out as we improve documentation around Deferred.

Michael Smith (JIRA)

unread,
Sep 27, 2018, 7:39:05 PM9/27/18
to puppe...@googlegroups.com
Michael Smith commented on Bug PUP-9186

Actually still an issue after moving it to message.

Henrik Lindberg (JIRA)

unread,
Sep 28, 2018, 4:26:04 AM9/28/18
to puppe...@googlegroups.com

You cannot do something like this:

notify { "hello ${Deferred('pid', [])}": }

and expect that to have a title that is resolved on the agent - that is the id of the notify - it must be known when compiling.

You can also not do this:

notify { "test": message => "hello ${Deferred('pid', [])}" }

And expect that the entire message string is resolved and then formatted on the agent side. To be clear why this is the case; consider the semantics of string interpolation: "evaluate an expression, transform to string, and concatenate" - thus, when an instance of Deferred is interpolated it will naturally be transformed to its string form.

Thus, a Deferred inside of interpolation, (or inside an EPP template for that matter) will not mean that the string/template is resolved on the agent side.

You can do like in this example to make it work:

notify { "test": message => Deferred('sprintf', [ 'hello %d', Deferred('pid', [])]) }

or, use EPP:

notify { "test": message => Deferred('inline_epp', [ 'hello <%= pid([]) %> ' ]) }

That works because the wanted result is a string - for something that should return something that is not a string, the approach above must be used.

Agree this should be pointed out - it will probably be a common thing that people wonder how to do.

Henrik Lindberg (JIRA)

unread,
Sep 28, 2018, 4:34:04 AM9/28/18
to puppe...@googlegroups.com
Henrik Lindberg assigned an issue to Unassigned
 
Change By: Henrik Lindberg
Assignee: Henrik Lindberg

Ben Ford (JIRA)

unread,
Nov 12, 2019, 7:55:04 PM11/12/19
to puppe...@googlegroups.com
Ben Ford commented on Bug PUP-9186
 
Re: Deferred doesn't work in 'notify' resource

Henrik Lindberg before I re-open or open a new ticket, is there work towards making client side templates easier to do? It's a very similar problem, and I solved it the same way you did above, but Eric Sorenson thought that it was a dirty approach.

Henrik Lindberg (JIRA)

unread,
Nov 13, 2019, 4:52:03 AM11/13/19
to puppe...@googlegroups.com

Ben Ford Since this comes up again - I can think of one more magic solution:

When evaluating a template, it would evaluate normally, but would detect if it results in interpolating a Deferred - if it finds one, the interpolation stops and the template function would instead return a Deferred value to send to the agent. It would also need to track all referenced variables and create a map of those to include in the call. One bad thing about this somewhat magic behavior is that any side effects from the "exploratory evaluation" will have occured while compiling, and will occur again when evaluating the same on the agent side (but then in a different context).

I think a more explicit approach is better.

Reply all
Reply to author
Forward
0 new messages