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

Erb puppetresource '<%' vs '<%=' #257

Closed PierreR closed 5 years ago

PierreR commented 5 years ago

Given an erb file with such a line (note the missing equal after <%)

      KAFKA_ADVERTISED_HOST_NAME: <% @facts['ipaddress'] %>

puppetresources ( with the --showfile option) will happily display the ipddress facts:

      KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1

whereas puppet will generate this:

      KAFKA_ADVERTISED_HOST_NAME: 
bartavelle commented 5 years ago

Should work better now ...

PierreR commented 5 years ago

Would it be possible to keep the CRITICAL message but not the error in case of <% @facts['ipaddress'] %> ?

CRITICAL: At ./modules/application/manifests/docker/kafka.pp:9:5 the evaluation of template './modules/application/templates/kafka/docker-compose.erb' failed. Eval not implemented

ERROR: (docker.kafka.dev) undefined method `[]' for nil:NilClass
(erb):12:in `get_binding'
/nix/store/vna6y0b2s5v6glj0kkrxn95a7mcxz8jh-ruby-2.4.4/lib/ruby/2.4.0/erb.rb:896:in `eval'
/nix/store/vna6y0b2s5v6glj0kkrxn95a7mcxz8jh-ruby-2.4.4/lib/ruby/2.4.0/erb.rb:896:in `result'
/nix/store/s1hnsq31ak61gcwsqzipkv51z28s7yv8-language-puppet-1.4.0-data/share/ghc-8.4.3/x86_64-linux-ghc-8.4.3/language-puppet-1.4.0/ruby/hrubyerb.rb:117:in `runFromContent'
/nix/store/s1hnsq31ak61gcwsqzipkv51z28s7yv8-language-puppet-1.4.0-data/share/ghc-8.4.3/x86_64-linux-ghc-8.4.3/language-puppet-1.4.0/ruby/hrubyerb.rb:113:in `runFromFile'
 in ./modules/application/templates/kafka/docker-compose.erb at ./modules/application/manifests/docker/kafka.pp:9:5
bartavelle commented 5 years ago

Oh I did not think of this! I think the best thing to do would be to have the parser fail, so that it would fall back to the ruby backend.

bartavelle commented 5 years ago

I made the parser fail on statements. It should be alright now.

PierreR commented 5 years ago

Have you had a chance to look at the failing test ?

PierreR commented 5 years ago

"Eval not implemented" is now just a log "INFO". I am not sure what do to about this but in this case it would be quite handy to have a WARNING.

bartavelle commented 5 years ago

It should use the actual ruby interpreter and produce the correct result, so I do not think this should be a warning (it is the expected behaviour).