Ruby 在puppet模板中加载特定于环境的变量

Ruby 在puppet模板中加载特定于环境的变量,ruby,puppet,Ruby,Puppet,我正在尝试在puppet模块中配置属性文件。属性文件应以如下内容结束: server_url=https://my-login.com/server token_url=https://my-login.com/token client_id=my-application server_url=<%=@server_url%> token_url=<%=@token_url%> client_id=my-application # $env will be DEV,

我正在尝试在puppet模块中配置属性文件。属性文件应以如下内容结束:

server_url=https://my-login.com/server
token_url=https://my-login.com/token
client_id=my-application
server_url=<%=@server_url%>
token_url=<%=@token_url%>
client_id=my-application
# $env will be DEV, STG or PRD
$server_url = 'https://my-login-dev.com/server'
$token_url = 'https://my-login-dev.com/token'
​
file {'/apps/my-application/common/client.properties':
  ensure  => 'present',
  content => template("common/client.properties.erb"),
}
我们将应用程序部署到多个环境(开发、暂存和生产),每个环境中的
服务器url
令牌url
将不同,但
客户端id
将始终相同。因此,我制作了一个erb模板,如下所示:

server_url=https://my-login.com/server
token_url=https://my-login.com/token
client_id=my-application
server_url=<%=@server_url%>
token_url=<%=@token_url%>
client_id=my-application
# $env will be DEV, STG or PRD
$server_url = 'https://my-login-dev.com/server'
$token_url = 'https://my-login-dev.com/token'
​
file {'/apps/my-application/common/client.properties':
  ensure  => 'present',
  content => template("common/client.properties.erb"),
}
我希望根据
env
变量的值设置
server\u url
token\u url
的值。理想情况下,这可以通过选择要包含的特定文件来实现。例如,为每个环境创建一个
url.properties
文件,从中加载变量。因此
url.properties.dev
将包含如下内容:

server_url=https://my-login.com/server
token_url=https://my-login.com/token
然后你可以这样写:

# server_url and token_url set up by the following line
include urls.properties.${env}

file {'/apps/my-application/common/client.properties':
  ensure  => 'present',
  content => template("common/client.properties.erb"),
}
我找不到任何关于如何做到这一点的文档,我也找不到一种通过黑客攻击来实现这一点的方法


有可能做到这一点吗?我是否应该采取另一种方法来解决这个问题?(我不想使用部分模板,因为我不想将文件分割成许多块)。

你这样做对自己来说比你需要的更难。您可以非常简单地通过为您的环境定制一个事实来解决这个问题。您按环境对服务器进行分类的惯例是什么?您已经检查过了吗?您正在使这种方式对自己造成比您需要的更大的困难。您可以非常简单地通过为您的环境定制一个事实来解决这个问题。您按环境对服务器进行分类的惯例是什么?您已经检查过了吗?