문제

It turns out I can't check for a node(host) name in Chef, so I'm trying to figure out the best way to make the following happen:

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

The idea is that when the node name (or some matching variable) is true, then it uses the ldap_access_node_filter, which is a unique value, else, it uses the default value. I'm basically configuring sssd config, and one of the hosts requires a special ldap access filter.

If there is a better way, please let me know.

Please help.

도움이 되었습니까?

해결책 2

Ohai should allow you to get hostname?

If you want something node specific it seems like you could just plug in to the attribute precedence in chef. You would set a default value for the attribute maybe at the cookbook level and then set an explicit attribute on the node. It also means if you need 2 of these servers to have the value you don't change the cookbook just the config on the servers.

다른 팁

Use

node.name

or

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

I just ran into this trying to deploy a special version of a file to one hostname. I used 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top