我正在创建一个脚本,它需要解析 puppet 输出的 yaml 输出。
当我再次请求示例https://puppet:8140/production/catalog/my.testserver.no 时,我会得到一些看起来像这样的 yaml:
--- &id001 !ruby/object:Puppet::Resource::Catalog
aliases: {}
applying: false
classes:
- s_baseconfig
...
edges:
- &id111 !ruby/object:Puppet::Relationship
source: &id047 !ruby/object:Puppet::Resource
catalog: *id001
exported:
等等...问题是当我执行 yaml.load(yamlstream) 时,我会收到如下错误:
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!ruby/object:Puppet::Resource::Catalog'
in "<string>", line 1, column 5:
--- &id001 !ruby/object:Puppet::Reso ...
^
据我所知,yaml 支持这个 &id001 部分。
有没有办法解决?我可以告诉 yaml 解析器忽略它们吗?我只需要 yaml 流中的几行,也许正则表达式是我的朋友?以前有人做过任何 yaml 清理正则表达式吗?
您可以使用 curl 获取 yaml 输出,例如:
curl --cert /var/lib/puppet/ssl/certs/$(hostname).pem --key /var/lib/puppet/ssl/private_keys/$(hostname).pem --cacert /var/lib/puppet/ssl/certs/ca.pem -H 'Accept: yaml' https://puppet:8140/production/catalog/$(hostname)
我还在 puppet 邮件列表 @ http://www.mail-archive.com/puppet-users@googlegroups.com/msg24143.html中找到了一些相关信息。但我无法让它正常工作......