puppet - puppet 资源如何在不编译失败的情况下检查 puppetmaster 上的数据源?
问题描述
我正在编写一个木偶 Ceph 部署模块,需要在管理节点上生成密钥并将它们分发到监控节点。我已经编写了服务器端函数来在生成密钥后检索它们,但只想在它们存在时分发这些密钥。
- 管理节点的清单生成集群密钥
- 监视器和管理节点的清单需要将这些密钥作为文件资源包含在内
- 如果尚未生成密钥,则清单不应无法编译(或生成过多的日志量)
- 文件资源需要命名,因为它们是其他资源的必备条件
nb 这些示例来自 Puppet3,因此没有 Ruby 调度 :(
收集和分发密钥的纯粹哲学方法是什么?
示例代码:manifests/admin_node.pp:
exec { "make_${cluster[name]}_${name}_keyring":
command => "/usr/bin/ceph-authtool --create-keyring ${ring[file]} --gen-key -n ${ring[name]} ${ring[auth]}",
require => [ File[$confdir, $bootdir], Package['ceph-common'], ],
creates => $ring[file],
}
lib/puppet/parser/functions/get_remote_file.rb:
module Puppet::Parser::Functions
newfunction(:get_remote_file, :type => :rvalue) do |args|
return "Error 3: " + args.length.to_s + " arguments were provided to get_remote_file.rb. Required is 3 to 5." if args.length < 3 or args.length > 5
remote_host = args[0]
remote_path = args[1]
local_path = args[2]
local_user = (args.length > 3) ? 'runuser -l ' + args[3] + ' ' : ''
remote_user = (args.length > 4) ? args[4] + '@' : ''
# Is the file already down?
return 0 if File.exist?(local_path)
`"#{local_user}bash -c 'scp #{remote_user}#{remote_host}:#{remote_path} #{local_path} 2> /dev/null'"`
return $?.exitstatus
end
end
清单/monitor_node.pp:
unless file_exists($master_key) {
get_remote_file($adm_node, $monitor_keyring, $master_key)
}
exec { "check_${cluster[name]}.mon.keyring":
command => '/bin/yes',
onlyif => "/usr/bin/test -e $master_key",
}
file { "$libdir/${cluster[name]}.mon.keyring":
ensure => $f_action,
source => "puppet:///modules/ceph$libdir/${cluster[name]}.mon.keyring",
require => Exec["check_${cluster[name]}.mon.keyring"],
}
感谢您提供有关如何解决此问题的任何想法。我知道这在 Puppet 中是……不鼓励的。什么是好方法?
解决方案
推荐阅读
- sql - 透视数据并将单列放入具有关联行的多列中
- javascript - 如何从 javascript 文件启动 android 服务
- c# - RSA解密异常:要解密的数据长度对于此密钥的大小无效
- c# - 我不明白这里的“新字符串”和 [i]
- php - mysql 在同一个mysql 插入中使用lastInsertID?
- vue.js - vue preset.json vue 创建消息
- javascript - 如何将回调的参数分配给全局变量?
- serilog - 使用 Serilog 保存到文件或本地数据库,哪个更好或更快?
- java - 如何在 Android Studio 中显示书籍列表?
- java - “AbstractButton 类型中的方法 addActionListener(ActionListener) 不适用于参数”错误