2

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.

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
wsani
  • 113
  • 2
  • 2
  • 5

3 Answers3

5

Use

node.name

or

node.name.split('.')[0]
Travis Bear
  • 13,039
  • 7
  • 42
  • 51
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.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
PatrickWalker
  • 550
  • 5
  • 19
1

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
jorfus
  • 2,804
  • 27
  • 23