1

我正在使用 Hiera(ruby 库,而不是命令行工具或 puppet 集成)从现有的一组 Hiera YAML(我们确实用于 puppet)中检索数据,以便在 Capistrano 中使用。我能够按预期工作......但我似乎无法摆脱似乎是默认的调试输出:

$ sudo cap deploy
WARN: 2014-10-29 12:17:09 +0000: Not using Hiera::Puppet_logger. It does not report itself to be suitable.
WARN: 2014-10-29 12:17:09 +0000: Cannot load backend puppet: cannot load such file -- hiera/backend/puppet_backend
DEBUG: 2014-10-29 12:17:09 +0000: Hiera YAML backend starting
DEBUG: 2014-10-29 12:17:09 +0000: Looking up package_repo_base in YAML backend
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source environments/PROD/LDN
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source regions/LDN
DEBUG: 2014-10-29 12:17:09 +0000: Cannot find datafile /etc/customer/hieradata/regions/LDN.yaml, skipping
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source environments/PROD
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source common
DEBUG: 2014-10-29 12:17:09 +0000: Found package_repo_base in common
WARN: 2014-10-29 12:17:09 +0000: Not using Hiera::Puppet_logger. It does not report itself to be suitable.
WARN: 2014-10-29 12:17:09 +0000: Cannot load backend puppet: cannot load such file -- hiera/backend/puppet_backend
DEBUG: 2014-10-29 12:17:09 +0000: Looking up puppet_deploy_base in YAML backend
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source environments/PROD/LDN
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source regions/LDN
DEBUG: 2014-10-29 12:17:09 +0000: Cannot find datafile /etc/customer/hieradata/regions/LDN.yaml, skipping
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source environments/PROD
DEBUG: 2014-10-29 12:17:09 +0000: Looking for data source common
DEBUG: 2014-10-29 12:17:09 +0000: Found puppet_deploy_base in common

**************************************************************************************************************************************************
* Recording output in: deploy.20141029-121709+0000.log *
**************************************************************************************************************************************************

  * 2014-10-29 12:17:09 executing `deploy'
  * 2014-10-29 12:17:09 executing `deploy:update'
 ** transaction: start

目前这只是一个烦恼,但扩展输出(我已经修剪了上面的输出)使日志记录相当嘈杂,我希望能够摆脱它。

4

1 回答 1

1

我设法通过在 deploy.rb 中的 hiera 调用中设置配置哈希来解决这个问题:

def hiera_lookup(key,default=nil,order_override=nil,resolution_type=:priority)
    hiera_yaml = File.realpath('./puppet/hiera.yaml')
    config = YAML.load_file(hiera_yaml)
    config[:logger] = 'noop'

    scope = YAML.load_file("/etc/hiera/hiera.conf")
    hiera = Hiera.new(:config => config)

    hiera.lookup("#{key}", default, scope, order_override, resolution_type)
end

config[:logger]键设置为“noop”完全抑制了 hiera 的输出。

于 2014-12-15T12:39:14.350 回答