https://www.puppet.com/community logo
Join Slack
Powered by
# puppet
  • m

    Massimiliano (Max)

    04/26/2022, 1:30 PM
    Copy code
    $networks = ['192.168.0.0', '192.168.10.0']
    $ports = ['udp:53', 'udp:57', 'udp:100']
    $networks.each | $net | {
      $combined = $ports.map |$net| { "${networks},${net}" }
    }
  • s

    Slackbot

    04/26/2022, 1:31 PM
    This message was deleted.
    b
    a
    • 3
    • 19
  • a

    Allahshukur Ahmadzada

    04/26/2022, 2:02 PM
    I am sure there are people facing this kind of issue, it would be perfect puppet had some kind of autorollback feature if run fails
  • b

    bastelfreak

    04/26/2022, 2:36 PM
    https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/service.pp
  • b

    bastelfreak

    04/26/2022, 2:37 PM
    or like this: https://github.com/saz/puppet-ssh/blob/master/manifests/server/config.pp#L28
  • m

    Massimiliano (Max)

    04/26/2022, 3:26 PM
    I'm not the best ruby programmer, hence here we go:
    Copy code
    Puppet::Functions.create_function(:'XXXX_iptables::combine_ip_port') do
      dispatch :combine_elements do
        param 'Array', :networks
        param 'Array', :ports
        return_type 'Array'
      end
    
    def combine_elements(networks, ports)
      length_networks = networks.length
      net_result = []
      net_hash = {}
      (1..length_networks).each do | net_count |
          array_count = net_count - 1
          net_hash[net_count] = ports.map { |string| "#{networks[array_count]},#{string}" }
      end
      net_hash.each do |net_key, net_value|
        net_result.push(net_hash[net_key])
      end
      
      net_result
    end
  • m

    Massimiliano (Max)

    04/26/2022, 3:32 PM
    I'm not the best ruby programmer, hence here we go:
    Copy code
    Puppet::Functions.create_function(:'geant_iptables::combine_ip_port') do
      dispatch :combine_elements do
        param 'Array', :networks
        param 'Array', :ports
        return_type 'Array'
      end
    
      def combine_elements(networks, ports)
        length_networks = networks.length
        result = []
        net_hash = {}
        (1..length_networks).each do |net_count|
          array_count = net_count - 1
          net_hash[net_count] = ports.map { |string| "#{networks[array_count]},#{string}" }
        end
        net_hash.each do |net_key, _net_value|
          net_result.push(net_hash[net_key])
        end
    
        result
      end
    end
  • m

    Massimiliano (Max)

    04/26/2022, 3:32 PM
    message has been deleted
  • m

    Massimiliano (Max)

    04/26/2022, 3:41 PM
    I'm not the best ruby programmer, hence here we go:
    Copy code
    Puppet::Functions.create_function(:'geant_iptables::combine_ip_port') do
      dispatch :combine_elements do
        param 'Array', :networks
        param 'Array', :ports
        return_type 'Array'
      end
    
      def combine_elements(networks, ports)
        length_networks = networks.length
        result = []
        net_hash = {}
        (1..length_networks).each do |net_count|
          array_count = net_count - 1
          net_hash[net_count] = ports.map { |string| "#{networks[array_count]},#{string}" }
        end
        net_hash.each do |net_key, _net_value|
          result.push(net_hash[net_key])
        end
    
        result
      end
    end
  • s

    Slackbot

    04/26/2022, 3:45 PM
    This message was deleted.
    l
    t
    • 3
    • 6
  • a

    Allahshukur Ahmadzada

    04/26/2022, 3:46 PM
    and it should somehow notify developer that module config failes
  • m

    Massimiliano (Max)

    04/26/2022, 3:54 PM
    I'm not the best ruby programmer, hence here we go:
    Copy code
    Puppet::Functions.create_function(:'geant_iptables::combine_ip_port') do
      dispatch :combine_elements do
        param 'Array', :networks
        param 'Array', :ports
        return_type 'Array'
      end
    
      def combine_elements(networks, ports)
        length_networks = networks.length
        result = []
        net_hash = {}
        (1..length_networks).each do |net_count|
          array_count = net_count - 1
          net_hash[net_count] = ports.map { |string| "#{networks[array_count]},#{string}" }
        end
        net_hash.each do |net_key, _net_value|
          result.push(net_hash[net_key])
        end
    
        result.flatten
      end
    end
  • d

    Dr Bunsen Honeydew

    04/26/2022, 4:45 PM
    meeting 🧑‍🏫Puppet Core Team is about to start up in #CFD8Z9A4T
  • h

    hbui

    04/26/2022, 6:19 PM
    Question about puppet-lint, does anyone know the 'why' of this test: http://puppet-lint.com/checks/selector_inside_resource/ As in, why is it bad to have conditionals in resource declarations or in parameter defaults?
  • n

    natemccurdy

    04/26/2022, 6:23 PM
    Because when used in excess, it’s difficult to read.
  • h

    hbui

    04/26/2022, 6:25 PM
    good to know
  • h

    hbui

    04/26/2022, 6:35 PM
    we have some of that and some code authors that like it
  • h

    hbui

    04/26/2022, 6:39 PM
    I was wondering more about whether support for that type of thing would go away with a later puppet release or if it behaved in indeterminate ways or something that would carry more weight than readability
  • n

    natemccurdy

    04/26/2022, 6:41 PM
    Oh, no, support for that will almost certainly not go away. The DSL is written to support use cases like that, it’s just that over time as people have had to refactor, test, validate, and build upon their own code, a best practice has developed to help make those tasks easier.
  • n

    natemccurdy

    04/26/2022, 6:43 PM
    Essentially, it’s the same reason that we have Puppet modules and individual classes, defines, and types. Sure, you could put all of your Puppet code in a single manifest with a mountain of conditional logic to make it work in a large complex environment, but no one would ever do that because it’s a maintenance nightmare.
  • n

    natemccurdy

    04/26/2022, 6:43 PM
    Essentially, it’s the same reason that we have Puppet modules and individual classes, defines, and types. Sure, you could put all of your Puppet code in a single manifest with a mountain of conditional logic to make it work in a large complex environment, but no one would ever do that because it’s a maintenance nightmare.
  • n

    natemccurdy

    04/26/2022, 6:43 PM
    So instead we design modular code with clear inputs and output that can be pieced together in a logical way that makes it easier to refactor, test, validate, and build upon.
  • r

    Robert Emanuele

    04/26/2022, 7:29 PM
    How do I access trusted facts with Facter.value?
  • n

    natemccurdy

    04/26/2022, 7:32 PM
    You can’t… at least not out of the box. “trusted facts”, contrary to their name, are not actually facts.
  • n

    natemccurdy

    04/26/2022, 7:32 PM
    They’re top-scope variables added during catalog compilation in the
    $trusted
    hash. But this module from the Forge adds them as local facts, which means you can access them with `Facter.value()`: https://forge.puppet.com/modules/jesse/certificate_extensions_facts
  • b

    bastelfreak

    04/26/2022, 7:33 PM
    do you want to use them in another fact or in a type/provider/function?
  • r

    Robert Emanuele

    04/26/2022, 7:34 PM
    Yes, I was trying to get the domain or certname to use them in another fact.
  • b

    bastelfreak

    04/26/2022, 7:34 PM
    the latter could work in theory 🤔
  • b

    bastelfreak

    04/26/2022, 7:34 PM
    ah
1...8910...428Latest