Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

Hiera, yaml and anchors

$
0
0
Hi, I have a data-set in my Hiera yaml file that has a couple of repetitions I'd like to reduce. [Yaml allows anchors](https://en.wikipedia.org/wiki/YAML#Repeated_nodes) to refer to defined data-sets. Settings this in the Yaml file in the hiera backend like below, works and hiera delivers back all values in the hash: # yaml file class::parameter: 127.0.0.1: secret: testing 123 shortname: localhost nastype: other 192.168.1.219: secret: testing123 shortname: localbox 10.5.128.0/24: &id001 secret: password nastype: A shortname: private-network 192.168.53.0/24: *id001 192.168.57.0/24: *id001 $ hiera 'class:parameter' {"127.0.0.1"=> {"secret"=>"testing 123", "shortname"=>"localhost", "nastype"=>"other"}, "192.168.1.219"=>{"secret"=>"testing123", "shortname"=>"localbox"}, "10.5.128.0/24"=> {"secret"=>"password", "nastype"=>"A", "shortname"=>"private-network"}, "192.168.53.0/24"=> {"secret"=>"password", "nastype"=>"A", "shortname"=>"private-network"}, "192.168.57.0/24"=> {"secret"=>"password", "nastype"=>"A", "shortname"=>"private-network"}, } If, however, I try to overwrite a value in a referenced set, Hiera throws me an error: # Added line in yaml file 85.119.140.2/32: *id001 shortname: non-private-network # Hiera error: $ hiera 'class:parameter' /.rvm/gems/ruby-2.0.0-p247/gems/psych-2.0.13/lib/psych.rb:370:in `parse': (): did not find expected key while parsing a block mapping at line 517 column 3 (Psych::SyntaxError) from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/psych-2.0.13/lib/psych.rb:370:in `parse_stream' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/psych-2.0.13/lib/psych.rb:318:in `parse' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/psych-2.0.13/lib/psych.rb:245:in `load' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend/yaml_backend.rb:19:in `block (2 levels) in lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/filecache.rb:53:in `read_file' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend/yaml_backend.rb:18:in `block in lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:120:in `block in datasourcefiles' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:92:in `block in datasources' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:90:in `map' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:90:in `datasources' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:115:in `datasourcefiles' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend/yaml_backend.rb:17:in `lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:266:in `block (2 levels) in lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:265:in `catch' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:265:in `block in lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:260:in `each' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera/backend.rb:260:in `lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/lib/hiera.rb:113:in `lookup' from /home/jt/.rvm/gems/ruby-2.0.0-p247/gems/hiera-2.0.0/bin/hiera:246:in `' from /home/jt/.rvm/gems/ruby-2.0.0-p247/bin/hiera:23:in `load' from /home/jt/.rvm/gems/ruby-2.0.0-p247/bin/hiera:23:in `
' from /home/jt/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval' from /home/jt/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `
' This error is related to the reference _*id001_ used. Using removing that for the entry *85.119.140.2/32* gets the thing working again. The current workaround for me is to remove the reference on those entries, which have altered settings (like *85.119.140.2/32* and set all of them again. This is not that pretty, but gets the job done. Is there any other way of doing this, am I doing it right or is my approach already f*cked up from the start? Regards, Daniel

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>