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

Add Ranges to DSL



    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: PUP 4.5.2
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
    • Environment:


    • Template:
    • Acceptance Criteria:

      Create an array of 1000 namevars in the Puppet DSL in less than 5 lines (assuming a line is max 80 characters long)

      Create an array of 1000 namevars in the Puppet DSL in less than 5 lines (assuming a line is max 80 characters long)


      Add ranges to the puppet DSL

      Currently for a resource that may take a number as a namevar, declaring multiple resources looks something like this:

      resource { ['1', '2', '3', '4', '5']:
          ensure => present,

      This is easy for small numbers of resources, but when declaring 100s or 1000s of these types of resources its get very tiresome to type (or script) the values needed and paste them in. What I am suggesting is a range operator to populate an array with the values of a range. Something like this:

      $a = range(1, 5)
      resource { $a:
          ensure => present,

      This may not be a big deal for small use-cases, but we have a situation where we are declaring upwards of a 100 resources and the following manifest would be much easier to maintain:

      $a = range(143, 567)
      resource { $a:
          ensure => present,

      I have a work-around for my implementation which parses the namevar as if its a range and handles the management of multiple resources in the provider, however this method is very hacky and prevents me from using self.instances and self.prefetch as they operate under the assumption that only a single resource is used.

      My implementation looks like this:

      resource { '143-567':
          ensure => present,

      An alternative solution to the same problem is to support more looping than just iterations. For example if I have two part namevars (which I also have), for example a location and an ip make up the name var, I could generate an array that way. For example, instead of this:

      $vars = ['name', 'name', 'name2', 'name2']
      resource { $vars:
          ensure => present,

      We generate an array: (This is Ruby, not DSL, I don't know how this would look in DSL)

      vars = []
      range(1, 2).each do |i|
        vars.append("name 10.10.10.#{i}")
        vars.append("name2 10.10.10.#{i}")

      Which can easily scale to:

      vars = []
      range(0, 255).each do |i|
        vars.append("name 10.10.10.#{i}")
        vars.append("name2 10.10.10.#{i}")
        vars.append("name3 10.10.10.#{i}")
        vars.append("name4 10.10.10.#{i}")

      To manage a huge amount of resources. My current implementation looks like this: (Also handles multiple resources through a single provider)

      resource { 'name1':
          ensure => present,
      resource { 'name4':
          ensure => present,

      I think that ranges and more advanced looping would be a great addition to the Puppet DSL, especially in fields like networking where we deal with managing large volumes of IP related resources.




            Unassigned Unassigned
            kylec Kyle Chickering
            0 Vote for this issue
            2 Start watching this issue



                Zendesk Support