- From: Andrew Brown <
>
- To: "
" <
>
- Subject: [chef] Re: Configure server to integer mapping
- Date: Thu, 30 Oct 2014 07:57:53 +0000
- Accept-language: en-US, en-CA
Hi Bryan,
You could also store the entire cluster configuration in Chef, and pull
out the node’s ID based on the IP address/hostname/etc.
For example:
default['zk']['cluster']['192.168.1.20']['id'] = 1
default['zk']['cluster']['192.168.1.21']['id'] = 2
default['zk']['cluster']['192.168.1.22']['id'] = 3
ip = node['ipaddress']
myid = node['zk']['cluster'][ip]['id']
if myid.nil?
raise 'Cannot find ME in cluster'
end
template '/etc/zookeeper/conf/myid' do
variables({ :myid => myid })
end
# Template contents
<%= @myid %>
--
Cheers,
Andrew
On 2014-10-29, 10:50 PM,
"
"
<
>
wrote:
>
Hi everyone,
>
>
For a few services like zookeeper or kafka, they require a server to
>
integer
>
mapping like this,
>
>
server a - 1
>
server b - 2
>
...
>
>
This is particularly difficult to do in Chef (outside of manually
>
configuring
>
this) using things like search. Some methods I have tried or seen,
>
>
1. Search for nodes and sort nodes by name. Use the index of each server
>
as
>
their id. This can cause servers to use the same id for a moment if
>
provisioning servers concurrently. This can also cause problems if a new
>
node
>
doesn't get appended to the end causing a number of servers to change
>
their
>
ids.
>
>
2. Convert ipaddress or some other attribute into an integer.
>
Unfortunately
>
this produces an integer too large as services like zookeeper only allow
>
ids
>
between 0-255.
>
>
3. Set this id on the node during provisioning and track the current id
>
somewhere. Then you can use search to just get the mapping.
>
>
Does anyone have other suggestions? It seems like 3 is the best option
>
though
>
not terrible easy to do. It could be easier than I think if I use
>
something
>
like chef-metal and define each machine with an id.
>
>
Bryan
Archive powered by MHonArc 2.6.16.