我不确定是否有办法在木偶中做到这一点,但这就是我想要做的。
根据这个木偶类的定义..。
class make_files (
$rabbit_servers = ['rabbit-1','rabbit-2'],
$mongo_servers = ['mongo-1','mongo-2'],
) {
...
}..。生成文件..。
# pwd
/root/conf/hosts
# more rabbit-*
::::::::::::::
rabbit-1.cfg
::::::::::::::
define host {
use linux-server
host_name rabbit-1
alias Rabbit MQ host
hostgroups rabbit_hosts
address 10.29.103.33
}
::::::::::::::
rabbit-2.cfg
::::::::::::::
define host {
use linux-server
host_name rabbit-2
alias Rabbit MQ host
hostgroups rabbit_hosts
address 10.29.103.34
}
# more mongo-*
::::::::::::::
mongo-1.cfg
::::::::::::::
define host {
use linux-server
host_name mongo-1
alias Mongo DB host
hostgroups mongo_hosts
address 10.29.103.31
}
::::::::::::::
mongo-2.cfg
::::::::::::::
define host {
use linux-server
host_name mongo-2
alias Mongo DB host
hostgroups mongo_hosts
address 10.29.103.32
}其中IP地址是对应主机的IP地址。
任何帮助都是非常感谢的。
发布于 2015-04-24 17:13:08
我找到了解决办法..。
class make_files (
$rabbit_servers = ['rabbit-1:10.29.103.33','rabbit-2:10.29.103.34'],
$mongo_servers = ['ost-mongo-el7-001:10.29.103.31'],
) {
define my_file ($content, $hostgroup) {
$tuple = split($name, ':')
$host_name = $tuple[0]
$file_name = "/tmp/$host_name.cfg"
$ipaddress = $tuple[1]
$config = "define host {
use linux-server
host_name $host_name
alias $host_name
hostgroups $hostgroup
address $ipaddress
}"
file { $file_name:
ensure => file,
content => $config,
}
}
$rabbit_content = join($rabbit_servers, ',')
my_file { $rabbit_servers: content => $rabbit_content, hostgroup => 'rabbit_hosts' }
$mongo_content = join($mongo_servers, ',')
my_file { $mongo_servers: content => $mongo_content, hostgroup => 'mongo_hosts' }
}..。我发现我需要稍微修改一下文件的内容。这可能不是最好的答案,但似乎奏效了。我愿意接受所建议的改进。
谢谢
发布于 2015-04-26 23:04:43
如果名称属于由木偶管理的节点,则可以使用PuppetDB直接从傀儡查询模块获取地址
$ipaddress = query_facts("hostname=$host_name", ['ipaddress'])['ipaddress']代码未经测试,我不确定调用是否正确。
https://stackoverflow.com/questions/29851915
复制相似问题