服务器 Gind.cn

服务器问题集锦,包括 Linux(Ubuntu, Centos,Debian等)和Windows Server服务器

Puppet – 从清单中调用自定义函数(包含case / when)

我正在对我的httpd和nginx虚拟主机confs进行puppetizing。 现在我有5个服务器,每个都有自己的端口,并运行在server1上,而nginx运行在server2上。 很明显,我需要保持对httpd和nginx的清单调用,因为它们可以在不同的服务器上运行。 我试图做的是共享两个清单之间的端口,所以我需要做的就是将我想要的虚拟主机的名称传递给httpd和nginx,它将在中心位置查找端口。 我正在尝试实现一个自定义函数,目前有这样的设置: # /path/to/puppet/modules/global/lib/puppet/parser/functions/app_to_port.rb module Puppet::Parser::Functions newfunction(:app_to_port, :type => :rvalue) do |args| case args[0] when app_1 return 27960 when app_2 return 27961 end end end # /path/to/puppet/modules/httpd/manifests/vhost/conf.pp … $vhost_port = app_to_port($name) … 我一直遇到各种问题,$ name我一直得到undefined local variable or method 'app_1'错误,如果我传入一个int, $vhost_portvariables永远不会得到一个值。 我是新来的ruby和傀儡,这导致我相信我缺less一些语言或应用程序构造。 我运行ruby -rpuppet /path/to/app_to_port.rb时没有任何回应,这让我相信代码在语法上是正确的。 为了logging,我正在阅读http://docs.puppetlabs.com/guides/custom_functions.html和https://stackoverflow.com/questions/948135/how-to-write-a-switch-statement-in – 让我知道这一点。 目前env:ruby1.8.7和木偶2.7.19