2014-02-24 241 views
1

原来我不能为您在厨师的节点(主机)的名字,所以我试图找出最好的方式作出如下发生:厨师检查主机名?

If hostname is X 
ldap_access_filter = memberOf=<%= node['sssd_ldap']['ldap_access_node_filter'] %> 
else 
ldap_access_filter = memberOf=<%= node['sssd_ldap']['ldap_access_filter'] %> 
end 

的想法是,当节点名称(或某个匹配变量)为true,则它使用ldap_access_node_filter,这是一个唯一值,否则它使用默认值。我基本上配置sssd配置,其中一个主机需要一个特殊的ldap访问过滤器。

如果有更好的方法,请让我知道。

请帮忙。

回答

1

Ohai应该让你获得主机名?

如果你想要一些特定的节点,看起来你可以插入厨师的属性优先级。您可以在食谱级别设置属性的默认值,然后在节点上设置显式属性。这也意味着,如果您需要这些服务器中的2个具有该值,那么您不会仅仅在服务器上更改该配置。

2

使用

node.name 

node.name.split('.')[0] 
0

我只是碰到了这个尝试将文件的一个特殊版本部署到一个主机名。我用not_if,only_if

cookbook_file 'file/to/replace' do 
    not_if {node.name == 'host.domain.name'} 
    source 'file_version.4' 
    action :create 
end 

cookbook_file '/file/to/replace' do 
    only_if {node.name == 'host.domain.name'} 
    source 'file_version.5' 
    action :create 
end