Jira (PUP-5778) dsl-defined functions should accept blocks

7 views
Skip to first unread message

Daniel Dreier (JIRA)

unread,
Jan 29, 2016, 6:27:02 PM1/29/16
to puppe...@googlegroups.com
Daniel Dreier created an issue
 
Puppet / Improvement PUP-5778
dsl-defined functions should accept blocks
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: Language
Created: 2016/01/29 3:26 PM
Priority: Normal Normal
Reporter: Daniel Dreier

I would like to write functions in the puppet language that accept a block of code, so that I can write my own iterators and other functions that accept code, without the context switch of doing it in ruby.

The specific use case I have is that we often need to run some piece of puppet code once among a group of nodes. To do that, we do a puppetdbquery to find similarly-classified nodes, then sort that list and see if the current node's certname is the first one on the list. If true, run some bit of code.

I would like to write a function like:

function runonce() {
  $pdb_leader = join([
    "group='${::group}'",
    "stage='${::stage}'",
    "function='${::function}'",
    "whereami='${::whereami}'",
  ], ' and ').query_nodes('certname').sort[0]
 
  if $::certname == $pdb_leader {
    yield()
  }
}

The way I might use this would be if I want to schedule a cron job to run on one of several identical web application servers:

runonce() {
  cron {'a job':
    # blah blah blah
   }
}

ping Henrik Lindberg because I think we've talked about this before

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.12#64027-sha1:e3691cc)
Atlassian logo

Eric Zounes (JIRA)

unread,
Jan 29, 2016, 6:39:02 PM1/29/16
to puppe...@googlegroups.com
Eric Zounes commented on Improvement PUP-5778
 
Re: dsl-defined functions should accept blocks

It sounds like what we really want is to have first-class functions sine we already have lambdas.

Henrik Lindberg (JIRA)

unread,
Jan 29, 2016, 6:50:06 PM1/29/16
to puppe...@googlegroups.com

In short - we are working on it (adding piece by piece).

This is a long standing goal. it consists of fixing a couple of things:

  • scope - scope is a very odd implementation so it is hard to do lambdas in general (this is not required though to make just calling a function written in puppet and giving it a block. It is however strictly forbidden to return such a block, or to bind it so that it survives the return from the function.
  • Puppet function - we have no syntax for defining that a puppet function accepts a block; we are working on that
  • Iterable support - in order to be able to write an iterable function it needs to be able to work in a chain of iterables. We just merged support for the types Iterable and Iterator and that will be in Puppet 4.4.0.
  • yield/call/next etc. block support - we lack functions or operators for this, we are designing these now.

Henrik Lindberg (JIRA)

unread,
Jan 29, 2016, 6:52:02 PM1/29/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
 
Change By: Henrik Lindberg
Scrum Team: Language

Henrik Lindberg (JIRA)

unread,
Jan 29, 2016, 6:57:02 PM1/29/16
to puppe...@googlegroups.com
 
Re: dsl-defined functions should accept blocks

Your use of runonce, must be written like this:

runonce() | | {
  cron {'a job':
    # blah blah blah
   }
}

Puppet requires an empty argument list in order to make a block out of the braced unit that follows the function call.

Daniel Dreier (JIRA)

unread,
Jan 29, 2016, 7:35:03 PM1/29/16
to puppe...@googlegroups.com
Daniel Dreier commented on Improvement PUP-5778

that sounds awesome. I'm really excited to play with what you come up with. I appreciate the detailed response.

Henrik Lindberg (JIRA)

unread,
Sep 7, 2016, 6:12:31 PM9/7/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Team: Puppet Developer Support
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
May 16, 2017, 9:00:03 AM5/16/17
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
May 16, 2017, 9:06:03 AM5/16/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Team: Puppet Developer Experience Agent

Henrik Lindberg (JIRA)

unread,
May 16, 2017, 9:06:04 AM5/16/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Fix Version/s: PUP 5.y

Henrik Lindberg (JIRA)

unread,
May 16, 2017, 9:07:04 AM5/16/17
to puppe...@googlegroups.com
Henrik Lindberg commented on Improvement PUP-5778
 
Re: dsl-defined functions should accept blocks

This needs to be blocked by a ticket to refactor the Scope implementation.
We also have a ticket about being able to call a Callable that should be linked with this ticket.

Josh Cooper (Jira)

unread,
Jan 27, 2021, 11:35:03 AM1/27/21
to puppe...@googlegroups.com
Josh Cooper commented on Improvement PUP-5778

This is related to supporting lambdas as described in PUP-4646.

This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

David McTavish (Jira)

unread,
Dec 6, 2021, 11:17:02 AM12/6/21
to puppe...@googlegroups.com
David McTavish updated an issue
 
Change By: David McTavish
Labels: final_triage
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

David McTavish (Jira)

unread,
Dec 6, 2021, 1:28:03 PM12/6/21
to puppe...@googlegroups.com
David McTavish updated an issue
Change By: David McTavish
Priority: Normal Low
Reply all
Reply to author
Forward
0 new messages