seperate node specific data from role
This commit is contained in:
parent
5f10663dc6
commit
399723ebea
@ -2,7 +2,8 @@
|
|||||||
#^syntax detection
|
#^syntax detection
|
||||||
site :opscode
|
site :opscode
|
||||||
|
|
||||||
cookbook 'apt'
|
cookbook "apt"
|
||||||
|
cookbook "minitest-handler"
|
||||||
|
|
||||||
def own_cookbook(name,opts={})
|
def own_cookbook(name,opts={})
|
||||||
opts = { path: "site-cookbooks/#{name}"}.merge!(opts)
|
opts = { path: "site-cookbooks/#{name}"}.merge!(opts)
|
||||||
@ -12,3 +13,4 @@ end
|
|||||||
own_cookbook "dhcp"
|
own_cookbook "dhcp"
|
||||||
own_cookbook "bind"
|
own_cookbook "bind"
|
||||||
own_cookbook "ntp"
|
own_cookbook "ntp"
|
||||||
|
own_cookbook "main"
|
||||||
|
2
Gemfile
2
Gemfile
@ -5,6 +5,8 @@ gem "chef"#, '~> 0.10.6'
|
|||||||
gem "pry-nav"
|
gem "pry-nav"
|
||||||
|
|
||||||
gem "chefspec"
|
gem "chefspec"
|
||||||
|
gem "minitest-chef-handler"
|
||||||
|
gem "fauxhai"
|
||||||
gem "rspec"
|
gem "rspec"
|
||||||
gem 'knife-spec'
|
gem 'knife-spec'
|
||||||
gem "berkshelf"
|
gem "berkshelf"
|
||||||
|
30
Vagrantfile
vendored
30
Vagrantfile
vendored
@ -4,9 +4,14 @@
|
|||||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||||
VAGRANTFILE_API_VERSION = "2"
|
VAGRANTFILE_API_VERSION = "2"
|
||||||
|
|
||||||
|
def load_json(name)
|
||||||
|
path = File.join(File.dirname(__FILE__), "nodes", name)
|
||||||
|
JSON.load(File.open(path))
|
||||||
|
end
|
||||||
|
|
||||||
boxes = [
|
boxes = [
|
||||||
{ name: "head_node", ip: '172.28.128.2', role: :head_node },
|
{ name: "node0.lctp", role: :head_node, mac: "5CA1AB1E0001", json: load_json("node0.json") },
|
||||||
#{ name: "compute_node", role: :compute_node, mac: "5CA1AB1E0001" }
|
{ name: "node1.lctp", role: :compute_node, mac: "5CA1AB1E0001", json: load_json("node1.json") }
|
||||||
]
|
]
|
||||||
|
|
||||||
["vbguest", "berkshelf"].each do |plugin|
|
["vbguest", "berkshelf"].each do |plugin|
|
||||||
@ -30,23 +35,32 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||||||
|
|
||||||
chef_default = proc do |chef|
|
chef_default = proc do |chef|
|
||||||
chef.cookbooks_path = "cookbooks"
|
chef.cookbooks_path = "cookbooks"
|
||||||
chef.roles_path = "roles"
|
|
||||||
chef.data_bags_path = "data_bags"
|
chef.data_bags_path = "data_bags"
|
||||||
|
chef.roles_path = "roles"
|
||||||
end
|
end
|
||||||
|
|
||||||
boxes.each do |box|
|
boxes.each do |box|
|
||||||
config.vm.define box[:name] do |node|
|
config.vm.define box[:name] do |node|
|
||||||
if box[:ip]
|
node.vm.provider :virtualbox do |vb|
|
||||||
node.vm.network :private_network, ip: box[:ip]
|
vb.gui = true
|
||||||
else
|
# 1. adapter: NAT to allow vagrant setup the machine
|
||||||
node.vm.network :private_network, type: :dhcp, mac: box[:mac]
|
# 2. adapter: for internal network between nodes
|
||||||
|
vb.customize ["modifyvm", :id,
|
||||||
|
"--nic1", "nat",
|
||||||
|
"--nictype1", "virtio",
|
||||||
|
"--nic2", "intnet",
|
||||||
|
"--nictype2", "virtio",
|
||||||
|
"--intnet2", "lctp",
|
||||||
|
"--macaddress2", box[:mac]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
node.vm.hostname = box[:name]
|
||||||
|
|
||||||
config.vm.provision :chef_solo do |chef|
|
config.vm.provision :chef_solo do |chef|
|
||||||
chef_default.call(chef)
|
chef_default.call(chef)
|
||||||
chef.add_role box[:role].to_s
|
chef.add_role box[:role].to_s
|
||||||
|
chef.json = box[:json]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
41
nodes/node0.json
Normal file
41
nodes/node0.json
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"main": {
|
||||||
|
"head_node": {
|
||||||
|
"internal_ip": "172.28.128.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dhcp" : {
|
||||||
|
"domain": {
|
||||||
|
"name": "lctp",
|
||||||
|
"server": "node0.lctp"
|
||||||
|
},
|
||||||
|
"interface": "eth1",
|
||||||
|
"subnet": {
|
||||||
|
"gateway": "node0.lctp",
|
||||||
|
"prefix": "172.28.128.0",
|
||||||
|
"netmask": "255.255.255.0"
|
||||||
|
},
|
||||||
|
"hosts": [{
|
||||||
|
"name": "node1",
|
||||||
|
"mac": "5c:a1:ab:1e:00:01",
|
||||||
|
"ip": "172.28.128.101"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"ntp" : {
|
||||||
|
"subnets": ["::1", "127.0.0.1", "172.28.128.0/24"]
|
||||||
|
},
|
||||||
|
"bind": {
|
||||||
|
"zones" : {
|
||||||
|
"lctp": {
|
||||||
|
"records": [
|
||||||
|
{ "name": "node0", "type": "A", "value": "172.28.128.1" },
|
||||||
|
{ "name": "node1", "type": "A", "value": "172.28.128.101" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"128.28.172.in-addr.arpa": {
|
||||||
|
"records": [{ "name": "101", "type": "PTR", "value": "node1" }]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"trusted_subnets": ["localhost", "localnets", "172.28.128.0/24"]
|
||||||
|
}
|
||||||
|
}
|
1
nodes/node1.json
Normal file
1
nodes/node1.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
@ -4,12 +4,8 @@
|
|||||||
"json_class": "Chef::Role",
|
"json_class": "Chef::Role",
|
||||||
"description": "Compute Node",
|
"description": "Compute Node",
|
||||||
"default_attributes": {
|
"default_attributes": {
|
||||||
"ntp": {
|
|
||||||
"server": "de.pool.ntp.org"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"run_list": [
|
"run_list": [
|
||||||
"recipe[apt]",
|
"recipe[main::compute_node]"
|
||||||
"recipe[ntp]"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,11 @@
|
|||||||
"json_class": "Chef::Role",
|
"json_class": "Chef::Role",
|
||||||
"description": "Head Node",
|
"description": "Head Node",
|
||||||
"default_attributes": {
|
"default_attributes": {
|
||||||
"dhcp" : {
|
"ntp": {
|
||||||
"hosts": [{
|
"server": "de.pool.ntp.org"
|
||||||
"name": "node0",
|
|
||||||
"mac": "5CA1AB1E0001",
|
|
||||||
"ip": "172.28.128.101"
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
"ntp" : {
|
|
||||||
"subnets": ["::1", "127.0.0.1", "172.28.128.0/24"]
|
|
||||||
},
|
|
||||||
"bind": {
|
|
||||||
"zones" : {
|
|
||||||
"lctp": {
|
|
||||||
"records": [{ "name": "node1", "type": "A", "value": "172.28.128.101" }]
|
|
||||||
},
|
|
||||||
"128.28.172.in-addr.arpa": {
|
|
||||||
"records": [{ "name": "101", "type": "PTR", "value": "node1" }]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"trusted_subnets": ["localhost", "localnets", "172.28.128.101"]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"run_list": [
|
"run_list": [
|
||||||
"recipe[apt]",
|
"recipe[main::head_node]"
|
||||||
"recipe[dhcp]",
|
|
||||||
"recipe[ntp]",
|
|
||||||
"recipe[bind]"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
10
site-cookbooks/bind/files/default/test/default_test.rb
Normal file
10
site-cookbooks/bind/files/default/test/default_test.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
require 'minitest/spec'
|
||||||
|
|
||||||
|
describe_recipe 'bind::default' do
|
||||||
|
it "starts the named daemon" do
|
||||||
|
assert_sh("service bind9 status")
|
||||||
|
end
|
||||||
|
it "should resolve dns" do
|
||||||
|
assert_sh("dig localhost @localhost")
|
||||||
|
end
|
||||||
|
end
|
@ -4,9 +4,7 @@
|
|||||||
4H ; retry
|
4H ; retry
|
||||||
3W ; expire
|
3W ; expire
|
||||||
1D ) ; minimun
|
1D ) ; minimun
|
||||||
NS <%= @node.hostname %>
|
NS <%= @node.fqdn %>.
|
||||||
|
|
||||||
<%= @node.hostname %> A <%= @node.ipaddress %>
|
|
||||||
|
|
||||||
<% @zone.records.each do |record| -%>
|
<% @zone.records.each do |record| -%>
|
||||||
<%= record.name %> <%= record.type %> <%= record.value %>
|
<%= record.name %> <%= record.type %> <%= record.value %>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
default.dhcp.domain.name = "lctp"
|
default.dhcp.domain.name = "privat"
|
||||||
default.dhcp.domain.server = "lctp"
|
default.dhcp.domain.server = "ns.privat"
|
||||||
default.hosts = []
|
default.dhcp.hosts = []
|
||||||
|
default.dhcp.interface = "eth0"
|
||||||
|
default.dhcp.subnet.prefix = "192.168.2.0"
|
||||||
|
default.dhcp.subnet.netmask = "255.255.255.0"
|
||||||
|
default.dhcp.subnet.gateway = "192.168.2.1"
|
||||||
|
10
site-cookbooks/dhcp/files/default/test/default_test.rb
Normal file
10
site-cookbooks/dhcp/files/default/test/default_test.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
require 'minitest/spec'
|
||||||
|
|
||||||
|
describe_recipe 'dhcp::default' do
|
||||||
|
it "starts the named daemon" do
|
||||||
|
assert_sh("service isc-dhcp-server status")
|
||||||
|
end
|
||||||
|
it "should resolve dns" do
|
||||||
|
assert_sh("dig localhost @localhost")
|
||||||
|
end
|
||||||
|
end
|
@ -2,8 +2,24 @@ include_recipe "apt"
|
|||||||
|
|
||||||
package "isc-dhcp-server"
|
package "isc-dhcp-server"
|
||||||
|
|
||||||
template "/etc/dhcpcd.conf" do
|
template "/etc/dhcp/dhcpd.conf" do
|
||||||
owner "root"
|
owner "root"
|
||||||
group "root"
|
group "root"
|
||||||
|
mode "0664"
|
||||||
source "dhcpd.conf.erb"
|
source "dhcpd.conf.erb"
|
||||||
|
notifies :reload, "service[isc-dhcp-server]"
|
||||||
|
end
|
||||||
|
|
||||||
|
template "/etc/default/isc-dhcp-server" do
|
||||||
|
owner "root"
|
||||||
|
group "root"
|
||||||
|
mode "0664"
|
||||||
|
source "isc-dhcp-server.erb"
|
||||||
|
notifies :reload, "service[isc-dhcp-server]"
|
||||||
|
end
|
||||||
|
|
||||||
|
service "isc-dhcp-server" do
|
||||||
|
provider Chef::Provider::Service::Upstart
|
||||||
|
action [:enable, :start]
|
||||||
|
supports status: true, start: true, stop: true, restart: true
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
# Crontab for <%= @node.name %> managed by Chef. Changes will be overwritten.
|
# dhcpd.conf for <%= @node.name %> managed by Chef. Changes will be overwritten.
|
||||||
default-lease-time 600;
|
default-lease-time 600;
|
||||||
max-lease-time 7200;
|
max-lease-time 7200;
|
||||||
# option definitions common to all supported networks...
|
# option definitions common to all supported networks...
|
||||||
option domain-name <%= @node.dhcp.domain.name %>;
|
option domain-name <%= @node.dhcp.domain.name %>;
|
||||||
option domain-name-servers <%= @node.dhcp.domain.server %>;
|
option domain-name-servers <%= @node.dhcp.domain.server %>;
|
||||||
|
|
||||||
|
subnet <%= @node.dhcp.subnet.prefix %> netmask <%= @node.dhcp.subnet.netmask%> {
|
||||||
|
option routers <%= @node.dhcp.subnet.gateway%>;
|
||||||
|
}
|
||||||
|
|
||||||
<% @node.dhcp.hosts.each do |host| -%>
|
<% @node.dhcp.hosts.each do |host| -%>
|
||||||
host <%= host.name %> {
|
host <%= host.name %> {
|
||||||
hardware ethernet <%= host.mac %>;
|
hardware ethernet <%= host.mac %>;
|
||||||
fixed-address <%= "#{host.name}.#{@node.dhcp.domain.name}" %>;
|
fixed-address <%= "#{host.name}.#{@node.dhcp.domain.name}" %>;
|
||||||
use-host-decl-names true;
|
use-host-decl-names true;
|
||||||
next-server <%= host.ip %>;
|
}
|
||||||
}
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
# /etc/default/isc-dhcp-server for <%= @node.name %> managed by Chef. Changes will be overwritten.
|
||||||
|
INTERFACES="<%= @node.dhcp.interface %>"
|
2
site-cookbooks/main/attributes/head_node.rb
Normal file
2
site-cookbooks/main/attributes/head_node.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
default.main.head_node.internal_ip = "192.168.2.1"
|
||||||
|
default.main.head_node.internal_network_device = "eth1"
|
6
site-cookbooks/main/metadata.rb
Normal file
6
site-cookbooks/main/metadata.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name "main"
|
||||||
|
depends "apt"
|
||||||
|
depends "ntp"
|
||||||
|
depends "dhcp"
|
||||||
|
depends "bind"
|
||||||
|
depends "minitest-handler"
|
3
site-cookbooks/main/recipes/compute_node.rb
Normal file
3
site-cookbooks/main/recipes/compute_node.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include_recipe "minitest-handler"
|
||||||
|
include_recipe "apt"
|
||||||
|
include_recipe "ntp"
|
10
site-cookbooks/main/recipes/head_node.rb
Normal file
10
site-cookbooks/main/recipes/head_node.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
include_recipe "minitest-handler"
|
||||||
|
include_recipe "apt"
|
||||||
|
include_recipe "ntp"
|
||||||
|
include_recipe "bind"
|
||||||
|
|
||||||
|
ifconfig node.main.head_node.internal_ip do
|
||||||
|
device node.main.head_node.internal_network_device
|
||||||
|
end
|
||||||
|
|
||||||
|
include_recipe "dhcp"
|
@ -5,14 +5,14 @@ describe 'dhcp::default' do
|
|||||||
ChefSpec::Runner.new do |node|
|
ChefSpec::Runner.new do |node|
|
||||||
node.set["dhcp"]["hosts"] =[{
|
node.set["dhcp"]["hosts"] =[{
|
||||||
name: "node0",
|
name: "node0",
|
||||||
mac: "5CA1AB1E0001",
|
mac: "5c:a1:ab:1e:00:01",
|
||||||
ip: "172.28.128.101"
|
ip: "172.28.128.101"
|
||||||
}]
|
}]
|
||||||
end.converge(described_recipe)
|
end.converge(described_recipe)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should setup dhcp" do
|
it "should setup dhcp" do
|
||||||
chef_run.should render_file("/etc/dhcpcd.conf").with_content("node0")
|
chef_run.should render_file("/etc/dhcp/dhcpd.conf").with_content("node0")
|
||||||
chef_run.should install_package("isc-dhcp-server")
|
chef_run.should install_package("isc-dhcp-server")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
30
spec/coobooks/main_spec.rb
Normal file
30
spec/coobooks/main_spec.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
|
describe 'main::head_node' do
|
||||||
|
let(:chef_run) do
|
||||||
|
ChefSpec::Runner.new do |node|
|
||||||
|
node.set["main"] = {
|
||||||
|
head_node: {
|
||||||
|
internal_ip: "10.10.1.1",
|
||||||
|
internal_network_device: "10.10.1.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end.converge(described_recipe)
|
||||||
|
end
|
||||||
|
it "should include cookbooks" do
|
||||||
|
expect(chef_run).should include_recipe('ntp')
|
||||||
|
expect(chef_run).should include_recipe('bind')
|
||||||
|
expect(chef_run).should include_recipe('dhcp')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'main::compute_node' do
|
||||||
|
let(:chef_run) do
|
||||||
|
ChefSpec::Runner.new do |node|
|
||||||
|
end.converge(described_recipe)
|
||||||
|
end
|
||||||
|
it "should include cookbooks" do
|
||||||
|
expect(chef_run).should include_recipe('apt')
|
||||||
|
expect(chef_run).should include_recipe('ntp')
|
||||||
|
end
|
||||||
|
end
|
@ -1,6 +1,7 @@
|
|||||||
require 'chefspec'
|
require 'chefspec'
|
||||||
require 'chefspec/berkshelf'
|
require 'chefspec/berkshelf'
|
||||||
require 'pry'
|
require 'pry'
|
||||||
|
require 'fauxhai'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.color_enabled = true
|
config.color_enabled = true
|
||||||
|
Loading…
Reference in New Issue
Block a user