Skip to content

Instantly share code, notes, and snippets.

@burtlo
Last active September 16, 2015 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burtlo/ce00756479101bb5fdac to your computer and use it in GitHub Desktop.
Save burtlo/ce00756479101bb5fdac to your computer and use it in GitHub Desktop.
Code Samples from the Online Class
name "win-production"
description "For Prods!"
cookbook "iis_demo", "= 0.1.0"
name "windows-dev"
description "For developers!"
cookbook "iis_demo", "= 0.2.0"
#
# Cookbook Name:: iis_demo
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
powershell_script 'Intall IIS' do
code 'add-windowsfeature Web-Server'
action :run
end
service 'w3svc' do
action [ :enable, :start ]
end
powershell_script "Disable Default Site" do
code 'get-website "Default Web Site*" | where {$_.state -ne "Stopped"} | Stop-Website'
end
node["iis_demo"]["sites"].each do |site_name, site_data|
site_dir = "#{ENV['SYSTEMDRIVE']}\\inetpub\\wwwroot\\#{site_name}"
directory site_dir
powershell_script "create app pool for #{site_name}" do
code "New-WebAppPool #{site_name}"
not_if "C:\\Windows\\System32\\inetsrv\\appcmd.exe list appPool #{site_name}"
end
powershell_script "new website for #{site_name}" do
code <<-PINEAPPLE
Import-Module WebAdministration
if(-not(test-path IIS:\\Sites\\#{site_name})) {
New-WebSite -name #{site_name} -Port #{site_data["port"]} -PhysicalPath #{site_dir} -ApplicationPool #{site_name}
}
PINEAPPLE
end
template "#{site_dir}\\Default.htm" do
source "Default.htm.erb"
rights :read, "Everyone"
variables(
:site_name => site_name,
:port => site_data["port"]
)
notifies :restart, "service[w3svc]"
end
end
<html>
<body>
<h2>We love <%= @site_name %></h2>
<h2><%= node["ipaddress"] %>:<%= @port %></h2>
</body>
</html>
name "core"
description "Core (Base) Linux role"
run_list "recipe[del_val]", "recipe[motd]", "recipe[users::create-users]", "recipe[ip-logger]"
name 'lin-webhead'
description 'Apache Web Server'
run_list "role[core]", "recipe[apache]"
name "win-webhead"
description "IIS Web Server"
run_list "recipe[iis_demo]"
default_attributes({
"iis_demo" => {
"sites" => {
"admins" => {
"port" => 8000
}
}
}
})
search("groups", "*:*").each do |group_data|
group group_data["id"] do
gid group_data["gid"]
members group_data["members"]
end
end
search("users", "platform:centos").each do |user_data|
user user_data["id"] do
comment user_data["comment"]
uid user_data["uid"]
gid user_data["gid"]
home user_data["home"]
shell user_data["shell"]
end
end
include_recipe "users::create-groups"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment