ripienaar/puppet-classifier

Data should be merged?

m4ce opened this issue · 4 comments

m4ce commented

Hi,

take the following example into consideration.

A machine has the following defined at the ENC level:

roles:
  - "custom1"
  - "custom2"

The classifier looks as follows:

  "Role: custom1":
    rules:
      - fact: "%{::roles}"
        operator: in
        value: "custom1"
    data:
      a::opts:
        var1: 1
  "Role: custom2":
    rules:
      - fact: "%{::roles}"
        operator: in
        value: "custom2"
    data:
      a::opts:
        var2: 1

I would expect the data to be merged when a node matches multiple rules. What do you think? I guess it should probably observe the lookup_options for that specific key?

m4ce commented

Sorry for this issue, it's actually already working as expected, user error :)

m4ce commented

Actually, I was right but testing that was getting a bit confusing.

I believe we should use deep_merge here rather than doing a soft merge.

  $data = $classification.reduce({}) |$r, $c| { deep_merge($r, $c["data"]) }

yeah that sounds reasonable to me

thanks, this should be on the forge now