Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5778

dsl-defined functions should accept blocks

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Accepted
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: PUP 5.y
    • Component/s: Language
    • Labels:
      None
    • Template:
    • Epic Link:
    • Sub-team:
    • Team:
      Froyo

      Description

      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

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            daniel.dreier Daniel Dreier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Zendesk Support