bartavelle / language-puppet

A library to work with Puppet manifests, test them and eventually replace everything ruby.
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link

String interpolation fails with dictionnary var above 2 levels `${os['key0']['key1]}` #260

Closed PierreR closed 5 years ago

PierreR commented 5 years ago
class application::foreman {  
  $test = $facts['os']['name']
  notify {"${test}":}                       <-- Works
  notify {"${facts['os']['name']}":}  <-- FAILS
}

The first notify works without problem and display the expected value 'RedHat'. The second fails with

ERROR: (foreman.dev) This data can't be indexed: facts at ...

Given the os facts is defined as in tests/default.yaml :

factsoverride:
  os:
    name: 'RedHat'

PS: this issue exist in previous releases such as v3.20.1

PierreR commented 5 years ago

As the added test shows, this issue is not about 'facts'. Anything above 2 levels will fail: notify {"${os['release']['major']}":}

PierreR commented 5 years ago

I believe the issue is on the parser:

> parseTest interpolableString "\"${os['architecture']}\"" 
[Lookup (Terminal (UVariableReference "os")) (Terminal (UString "architecture"))]

> parseTest interpolableString "\"${os['release']['major']}\"" 
[Lookup (Lookup (Terminal (UString "os")) (Terminal (UString "release"))) (Terminal (UString "major"))]
PierreR commented 5 years ago

@bartavelle I guess there is a better way to fix this than using makeExprParser ?