chef generate cookbook sddevops-custom-resources
cd sddevops-custom-resources
mkdir resources
#resources/website.rb
property :instance_name, String, name_property: true
property :port, Fixnum, required: true
provides :mysite
mysite 'foo' do
port 81
action :create
end
action :create do
package 'httpd' do
action :install
end
...
...
template "/etc/httpd/conf.d/httpd-#{instance_name}.conf" do
source "httpd.conf.erb"
variables(
:instance_name => instance_name,
:port => port
)
owner 'root'
group 'root'
mode '0644'
action :create
notifies :restart, 'service[httpd]'
end
directory "/var/www/vhosts/#{instance_name}" do
recursive true
owner 'root'
group 'root'
mode '0755'
action :create
notifies :restart, 'service[httpd]'
end
...
...
file "/var/www/vhosts/#{instance_name}/index.html" do
mode '0644'
content "Ohai! This is the #{instance_name} site running on port #{port}."
action :create
end
service 'httpd' do
action [:enable, :start]
end
end
mkdir templates
Listen <%= @port %>
<VirtualHost *:<%= @port %>>
DocumentRoot "/var/www/vhosts/<%= @instance_name %>"
ServerName <%= node['fqdn'] %>
</VirtualHost>
#recipes/default.rb
mysite 'foo' do
port 81
action :create
end
- name: ubuntu-14.04 <--- take this out
- name: centos-7.1
chef install (chefdk 0.9+)
kitchen converge
kitchen login
curl localhost:81
# test/integration/default/serverspec/default_spec.rb
require 'spec_helper'
describe port(81) do
it { should be_listening }
end
describe port(82) do
it { should be_listening }
end
kitchen verify
...
mysite 'bar' do
port 82
end
kitchen converge
kitchen verify
- name: centos-6.7 <--- add this
- name: centos-7.1
kitchen test -c