[cleaned up excessive Re’s]
Hi Maciej,
Sorry to take so long to respond. Mapping IPs to nodes is probably going to be the most cumbersome part of this. The best way I can think of to do this (others are encouraged to chime in with better suggestions because mine feels a bit clunky) is either to create a data bag with node name to IP mappings and then have the server look up its own entry in the data bag at bootstrap and assign the IP accordingly, or to use Chef to manage a DHCP server and then assign the IPs from there.
Here's how you would do it with a data bag:
my_ips = data_bag_item('example_networking_bag', 'node_ips')[node.name]
include_recipe 'network_interfaces'
my_ips.each do |interface, if_conf|
network_interface interface do
target if_conf['ipaddr']
mask if_conf['netmask']
gateway if_conf['gateway']
pre_up 'sleep 2' # in keeping with default behavior on Debian/Ubuntu.
end
end
...and the data bag item would look something like this:
{
"id": "node_ips",
"my-first-node-name": {
"eth0": {
"ipaddr": "192.168.1.2",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1"
},
"eth1": {
"ipaddr": "192.168.2.3",
"netmask": "255.255.255.0",
"gateway": "192.168.2.1"
},
},
"my-second-node-name": {
"eth0": {
"ipaddr": "192.168.1.3",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1"
},
"eth1": {
"ipaddr": "192.168.2.4",
"netmask": "255.255.255.0",
"gateway": "192.168.2.1"
}
}
}
Does that make sense?
--
On March 21, 2014 at 1:21:25 PM,
(
">
) wrote:
Hi Eric,
This seems to be the direction I want to follow, I now
understand how are you achieving certain things, however I still
don’t see how is this applied to multiple nodes? Let’s assume that
each machine needs to have static IPs assigned to it’s NICs, how
would you achieve that?
Best regards,
Maciej
Hi Maciek,
So there are a lot of possible ways to do this, but I suppose the
first thing I’d need to know is whether these interfaces need to be
set up with static addresses or dynamic ones, and whether all 4
interfaces in the example would need to have different
setups.
The simplest thing to do would be to just define a both interfaces
using DHCP in a single wrapper cookbook and then place that wrapper
cookbook in the run list of both nodes. That might look
something like this:
include_recipe 'network_interfaces'
%w(eth0 eth1).each do |alias|
network_interface alias do
bootproto 'dhcp'
end
end
Obviously if you want to specify static IPs per node that’s going
to require some finagling. The right way to do it will be
determined by exactly how you want to allocate IPs. If you
can give me some feedback on this I might be able to give you some
suggestions.
Almost any property that can be specified in the
/etc/network/interfaces config file will be listed in the resource
definition:
https://github.com/redguide/network_interfaces/blob/v1.0.0/resources/default.rb
…And one day will also be listed in the README. ;-)
Also, anything that is not included in that resources file can be
added by setting the “custom” property with a hash.
E.g.
network_interface 'eth0'
do
target '192.168.0.1'
custom(
'myproperty1' => 'myvalue1',
'myproperty2' =>
'myvalue2'
)
end
Please let me know if any of that isn’t clear or if I left out
something you need.
On March 20, 2014 at 6:05:18 PM,
Maciek Misztal (
" target="_parent">
) wrote:
Hi Eric,
If you would be so kind and elaborate :
How would you configure multiple nodes with multiple
interfaces using this cookbook? Can you give me a simple 2 nodes
with 2 interfaces each example?
Please assume that I know little of chef and I'm trying
to understand how to "model" the whole thing - while I have some
experience with ruby, not much but sufficient for rake/chef etc.
;)
|