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>