1

Puppet で使用される ERB テンプレートで、ハッシュの YAML 出力を並べ替えて、常に同じ出力になるようにしようとしています。

これが私がこれまでに持っているものです(でmytest/templates/hash.erb):

<%=
  class MyHash < Hash
    def to_yaml( opts = {} )
      YAML::quick_emit( self, opts ) do |out|
        out.map( taguri, to_yaml_style ) do |map|
          keys.sort.each do |k|
            v = self[k]
            map.add( k, v )
          end
        end
      end
    end
  end
  myScope = scope.to_hash.reject{|k,v| k.to_s =~ /(uptime|timestamp|free)/}
  MyHash[myScope].to_yaml
-%>

これにより、次の結果が得られます。

$ puppet apply -e 'include mytest' --modulepath .
Failed to parse template mytest/hash.erb:
  Filepath: /usr/lib/ruby/1.8/yaml.rb
  Line: 391
  Detail: wrong argument type String (expected Data)
 at /home/rpinson/bas/puppet/mytest/manifests/init.pp:3 on node foo.example.com

これは の内容ですmytest/manifests/init.pp:

class mytest {
  notify { 'toto':
    message => template('mytest/hash.erb'),
  }
}

このタイプのデータがどこから来ているのか、これを機能させるためにパラメーターを適切にキャストする方法を理解できないようです…</p>

4

1 に答える 1

0

It turns out, the source of problem is ZAML, YAML replacement which Puppet uses for performance purposes.

It can be proved by testing this erb-template without Puppet.

I'm pretty sure it will work.

I'm investigating to allow to work them together.

UPDATE:

ZAML.dump(MyHash[myScope]) # instead of MyHash[myScope].to_yaml

This may heal problem, at least it does my one that really similar.

于 2013-06-14T17:30:40.630 に答える