Skip to content

Commit 27205e2

Browse files
authored
Merge pull request #1 from nweddle/2016-kitchen
Use dsc_resource with WS2016
2 parents fa98eeb + beaf616 commit 27205e2

File tree

6 files changed

+146
-45
lines changed

6 files changed

+146
-45
lines changed

.kitchen.ec2.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
driver:
3+
name: ec2
4+
aws_ssh_key_id: <%= ENV["EC2_SSH_KEY_NAME"] %>
5+
region: us-west-2
6+
availability_zone: us-west-2c
7+
security_group_ids: sg-401e0e25
8+
iam_profile_name: testKitchenAndKnifeEc2
9+
subnet_id: subnet-5b32ef02
10+
instance_type: m3.large
11+
associate_public_ip: true
12+
user_data: 'windows_user_data'
13+
tags:
14+
Name: "fourthcoffee-localdev-kitchen-instance"
15+
created-by: "test-kitchen"
16+
user: <%= ENV['USER'] %>
17+
X-Dept: Sales
18+
X-Contact: <%= ENV['USER'] %>
19+
X-Production: "false"
20+
21+
provisioner:
22+
name: chef_zero
23+
require_chef_omnibus: 12.19.36
24+
25+
verifier:
26+
name: inspec
27+
28+
platforms:
29+
- name: windows-2016
30+
driver_config:
31+
image_id: ami-94e26af4
32+
transport:
33+
ssh_key: <%= ENV["EC2_SSH_KEY_PATH"] %> # change it; this is needed so kitchen can retrieve the Admin password
34+
35+
suites:
36+
- name: default
37+
run_list:
38+
# The test cookbook is located in test/fixtures.
39+
# It is what puts secret keys, certs, etc. in place
40+
- recipe[fourthcoffee::default]
41+
# attributes:
42+
# demo:
43+
# domain_prefix: ''
44+
# domain: 'automate-demo.com'
45+
# enterprise: 'automate-demo'
46+
# org: 'automate'
47+
# hosts:
48+
# workstations: 1
49+
# workstation-number: 1
50+
# versions:
51+
# chefdk: 'stable-1.2.22'
52+
verifier:
53+
inspec_tests:
54+
- test/integration/default/inspec/controls

Berksfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ DEPENDENCIES
44
metadata: true
55

66
GRAPH
7-
chef_handler (1.4.0)
8-
fourthcoffee (0.1.1)
7+
fourthcoffee (0.2.0)
98
iis (>= 0.0.0)
109
windows (>= 0.0.0)
11-
iis (4.1.7)
12-
windows (>= 1.34.6)
13-
windows (1.41.0)
14-
chef_handler (>= 0.0.0)
10+
iis (6.0.1)
11+
windows (>= 2.0)
12+
ohai (5.0.3)
13+
windows (3.0.5)
14+
ohai (>= 4.0.0)

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
license 'Apache 2.0'
55
description 'Installs and configures the Fourth Coffee demonstration website'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '0.1.1'
7+
version '0.2.0'
88

99
source_url ''
1010
issues_url ''

recipes/_classic.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Cookbook Name:: fourthcoffee
3-
# Recipe:: default
3+
# Recipe:: _classic
44
#
55
# Copyright 2014, Chef Software, Inc.
66
#
@@ -22,7 +22,7 @@
2222
end
2323

2424
# Pre-requisite features for IIS-ASPNET45 that need to be installed first, in this order.
25-
%w{IIS-ISAPIFilter IIS-ISAPIExtensions NetFx3ServerFeatures NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45}.each do |f|
25+
%w(IIS-ISAPIFilter IIS-ISAPIExtensions NetFx3ServerFeatures NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45).each do |f|
2626
windows_feature f do
2727
action :install
2828
end
@@ -31,3 +31,7 @@
3131
windows_feature 'IIS-ASPNET45' do
3232
action :install
3333
end
34+
35+
windows_feature 'IIS-ManagementConsole' do
36+
action :install
37+
end

recipes/_dsc.rb

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Cookbook Name:: fourthcoffee
3-
# Recipe:: default
3+
# Recipe:: _dsc
44
#
55
# Copyright 2014, Chef Software, Inc.
66
#
@@ -18,49 +18,57 @@
1818
#
1919

2020
#
21-
# Use the WindowsFeature DSC resource to install Web-Server and Web-Asp-Net45
21+
# Use the 'dsc_resource' resource (requires WMF 5.0+)
2222
#
2323

24-
dsc_script 'Web-Server' do
25-
code <<-EOH
26-
WindowsFeature InstallWebServer
27-
{
28-
Name = "Web-Server"
29-
Ensure = "Present"
30-
}
31-
EOH
24+
dsc_resource 'webserver' do
25+
resource :windowsfeature
26+
property :name, 'Web-Server'
27+
property :ensure, 'Present'
3228
end
3329

34-
dsc_script 'Web-Asp-Net45' do
35-
code <<-EOH
36-
WindowsFeature InstallDotNet45
37-
{
38-
Name = "Web-Asp-Net45"
39-
Ensure = "Present"
40-
}
41-
EOH
30+
dsc_resource 'dotnet45' do
31+
resource :windowsfeature
32+
property :name, 'Web-Asp-Net45'
33+
property :ensure, 'Present'
4234
end
4335

44-
dsc_script 'Web-Mgmt-Console' do
45-
code <<-EOH
46-
WindowsFeature InstallIISConsole
47-
{
48-
Name = "Web-Mgmt-Console"
49-
Ensure = "Present"
50-
}
51-
EOH
36+
dsc_resource 'webmgmtconsole' do
37+
resource :windowsfeature
38+
property :name, 'Web-Mgmt-Console'
39+
property :ensure, 'Present'
5240
end
5341

54-
# You can also use dsc_resource (requires PS5)
42+
#
43+
# You can also use dsc_script (requires WMF 4.0+)
44+
#
5545

56-
# dsc_resource 'webserver' do
57-
# resource :windowsfeature
58-
# property :name, 'Web-Server'
59-
# property :ensure, 'Present'
46+
# dsc_script 'Web-Server' do
47+
# code <<-EOH
48+
# WindowsFeature InstallWebServer
49+
# {
50+
# Name = "Web-Server"
51+
# Ensure = "Present"
52+
# }
53+
# EOH
6054
# end
61-
62-
# dsc_resource 'dotnet45' do
63-
# resource :windowsfeature
64-
# property :name, 'Web-Asp-Net45'
65-
# property :ensure, 'Present'
55+
#
56+
# dsc_script 'Web-Asp-Net45' do
57+
# code <<-EOH
58+
# WindowsFeature InstallDotNet45
59+
# {
60+
# Name = "Web-Asp-Net45"
61+
# Ensure = "Present"
62+
# }
63+
# EOH
64+
# end
65+
#
66+
# dsc_script 'Web-Mgmt-Console' do
67+
# code <<-EOH
68+
# WindowsFeature InstallIISConsole
69+
# {
70+
# Name = "Web-Mgmt-Console"
71+
# Ensure = "Present"
72+
# }
73+
# EOH
6674
# end

windows_user_data

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<powershell>
2+
# Script based on examples in Bojan Rajkovic's Code Rinse Repeat blog.
3+
# Details: http://coderinserepeat.com/2015/07/15/chef-knife-ec2-and-knife-windows/
4+
5+
# Set our admin password
6+
# $admin = [adsi]("WinNT://./Administrator, user")
7+
# $admin.psbase.invoke("SetPassword", "Ch4ng3m3")
8+
# Turn on WinRM, make sure to relax its security a bit.
9+
# Please don't expose the WinRM port to the world on these machines.
10+
# I am not responsible for anything that happens if you do.
11+
winrm qc -q
12+
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
13+
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
14+
winrm set winrm/config/service/auth '@{Basic="true"}'
15+
# Make sure to trust all hosts
16+
Set-Item wsman:localhost\client\trustedhosts -value * -force
17+
# Turn off the Windows firewall. Its default WinRM rules only allow traffic from
18+
# hosts in your domain and from "private" networks. Its functionality is superseded
19+
# by security groups anyway.
20+
Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled False
21+
# Stop the WinRM service, make sure it autostarts on reboot, and start it
22+
net stop winrm
23+
sc.exe config winrm start=auto
24+
net start winrm
25+
26+
# Add the chef server's hostname to hosts file
27+
$chefserverip = "CHEF_SERVER_IP"
28+
$chefserverhostname = "chef.automate-demo.com"
29+
$automateserverip = "AUTOMATE_SERVER_IP"
30+
$automateserverhostname = "automate.automate-demo.com"
31+
$filename = "C:\Windows\System32\drivers\etc\hosts"
32+
$automateserverip + "`t`t" + $automateserverhostname | Out-File -encoding ASCII -append $filename
33+
$chefserverip + "`t`t" + $chefserverhostname | Out-File -encoding ASCII -append $filename
34+
35+
</powershell>

0 commit comments

Comments
 (0)