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

    binford2k

    08/04/2022, 10:46 PM
    puppet lookup profile::stream_web::config
  • p

    Patrick Rynhart

    08/04/2022, 10:46 PM
    Then I get
    Copy code
    Notice: {developmentb => {someattribute => here, anotherattribute => here}}
  • p

    Patrick Rynhart

    08/04/2022, 10:46 PM
    Copy code
    Notice: {developmentc => {someattribute => here, anotherattribute => here}}
  • b

    binford2k

    08/04/2022, 10:47 PM
    https://github.com/betadots/hdm will make this debugging so much easier
  • b

    binford2k

    08/04/2022, 10:47 PM
    https://github.com/betadots/hdm will make this debugging so much easier
  • p

    Patrick Rynhart

    08/04/2022, 10:47 PM
    Looks like I can’t access value via $value[‘someattribute’] but I don’t understand why
  • p

    Patrick Rynhart

    08/04/2022, 10:48 PM
    Sorry - this must be painful for you experienced puppet guys…
    ✅ 1
  • n

    natemccurdy

    08/04/2022, 10:51 PM
    I also recommend: • typing the lambda in the
    each
    loop, so that Puppet validates that each element matches that data type.
  • v

    vchepkov

    08/04/2022, 10:53 PM
    You don't have to use arrays in your data. I would use
    Copy code
    profile::stream_web::config:
      developmentb:
        someattribute: 'here'
        anotherattribute: 'here'
      developmentc:
        someattribute: 'here'
        anotherattribute: 'here'
    
    config.each | $deployment, $attrs | {
      notify { "${deployment}: someattribute: ${attr['someattribute']}": }
    }
    ✅ 1
  • n

    natemccurdy

    08/04/2022, 10:53 PM
    The Hash’s first-level key is
    developmentb
    , not
    someattribute
  • b

    binford2k

    08/04/2022, 10:53 PM
    you need to iterate on | $key, $value |
  • b

    binford2k

    08/04/2022, 10:54 PM
    you’re getting an array of single items instead of keys and values
  • p

    Patrick Rynhart

    08/04/2022, 10:54 PM
    ah right!
  • b

    binford2k

    08/04/2022, 10:54 PM
    yes, what @vchepkov said
  • p

    Patrick Rynhart

    08/04/2022, 10:54 PM
    I will try @vchepkov’s suggestion
  • v

    vchepkov

    08/04/2022, 10:54 PM
    You don't have to use arrays in your data. I would use
    Copy code
    profile::stream_web::config:
      developmentb:
        someattribute: 'here'
        anotherattribute: 'here'
      developmentc:
        someattribute: 'here'
        anotherattribute: 'here'
    
    config.each | $deployment, $attrs | {
      notify { "${deployment}: someattribute: ${attr['someattribute']}": }
    }
  • h

    helindbe

    08/04/2022, 10:55 PM
    What @natemccurdy said is what your problem is.
  • h

    helindbe

    08/04/2022, 10:59 PM
    if you do what @binford2k suggests on the array you will get 0, then 1, then 2 etc in $key.
  • b

    binford2k

    08/04/2022, 11:00 PM
    (and then fix the yaml so it’s the intended hash 😁)
  • p

    Patrick Rynhart

    08/04/2022, 11:02 PM
    Hmmm - So have changed my hiera to:
  • p

    Patrick Rynhart

    08/04/2022, 11:02 PM
    Copy code
    profile::stream_web::config:
      muc:
        'developmentb':
           someattribute: 'here'
           anotherattribute: 'here'
        'developmentc':
           someattribute: 'here'
           anotherattribute: 'here'
  • p

    Patrick Rynhart

    08/04/2022, 11:02 PM
    And my full manifest is currently:
  • p

    Patrick Rynhart

    08/04/2022, 11:02 PM
    Copy code
    class profile::stream_web (
      $config = [],
    ) {
    
      $muc = $config['muc']
      $muc.each | $value | {
        $d1 = $value['someattribute']
        notify { "$d1": }
      }
  • v

    vchepkov

    08/04/2022, 11:02 PM
    do you need 'muc' ? is there anything else on that level ?
  • p

    Patrick Rynhart

    08/04/2022, 11:03 PM
    Possibly making progress, but that results in: Evaluation Error: The value ‘someattribute’ cannot be converted to Numeric.
  • s

    Slackbot

    08/04/2022, 11:04 PM
    This message was deleted.
    ❤️ 1
    p
    • 2
    • 4
  • b

    binford2k

    08/04/2022, 11:05 PM
    start with one piece. The Hiera data is probably the easiest. What are you trying to achieve?
  • b

    binford2k

    08/04/2022, 11:05 PM
    the ability do do something like “get config data for deployment ‘developmentb’“?
    ✅ 1
  • b

    binford2k

    08/04/2022, 11:06 PM
    paste that yaml into something like https://codebeautify.org/yaml-parser-online and parse it
  • b

    binford2k

    08/04/2022, 11:06 PM
    see what data structure shows up on the right
1...122123124...428Latest