Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Commit 4805509

Browse files
author
Shay Bergmann
committed
initial commit
0 parents  commit 4805509

File tree

10 files changed

+279
-0
lines changed

10 files changed

+279
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.vagrant
2+
Berksfile.lock
3+
*~
4+
*#
5+
.#*
6+
\#*#
7+
.*.sw[a-z]
8+
*.un~
9+
/cookbooks
10+
11+
# Bundler
12+
Gemfile.lock
13+
bin/*
14+
.bundle/*
15+

Berksfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
site :opscode
2+
3+
metadata

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'berkshelf'
4+
gem 'thor-foodcritic'

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (C) 2013 Shay Bergmann
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# windows-hostname cookbook
2+
3+
Sets hostname and FQDN of a windows node.
4+
5+
# Requirements
6+
7+
A node running Windows
8+
9+
# Usage
10+
11+
Set `set_fqdn` to the desired FQDN on the node and include `recipe[windows-hostname]` in its runlist.
12+
13+
NOTE: WINDOWS WILL RESTART
14+
15+
# Attributes
16+
17+
set_fqdn - FQDN to set.
18+
19+
# Recipes
20+
21+
## default
22+
23+
# Author
24+
25+
Author:: Shay Bergmann (<[email protected]>)

Thorfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# encoding: utf-8
2+
3+
require 'bundler'
4+
require 'bundler/setup'
5+
require 'thor/foodcritic'
6+
require 'berkshelf/thor'

chefignore

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Put files/directories that should be ignored in this file when uploading
2+
# or sharing to the community site.
3+
# Lines that start with '# ' are comments.
4+
5+
# OS generated files #
6+
######################
7+
.DS_Store
8+
Icon?
9+
nohup.out
10+
ehthumbs.db
11+
Thumbs.db
12+
13+
# SASS #
14+
########
15+
.sass-cache
16+
17+
# EDITORS #
18+
###########
19+
\#*
20+
.#*
21+
*~
22+
*.sw[a-z]
23+
*.bak
24+
REVISION
25+
TAGS*
26+
tmtags
27+
*_flymake.*
28+
*_flymake
29+
*.tmproj
30+
.project
31+
.settings
32+
mkmf.log
33+
34+
## COMPILED ##
35+
##############
36+
a.out
37+
*.o
38+
*.pyc
39+
*.so
40+
*.com
41+
*.class
42+
*.dll
43+
*.exe
44+
*/rdoc/
45+
46+
# Testing #
47+
###########
48+
.watchr
49+
.rspec
50+
spec/*
51+
spec/fixtures/*
52+
test/*
53+
features/*
54+
Guardfile
55+
Procfile
56+
57+
# SCM #
58+
#######
59+
.git
60+
*/.git
61+
.gitignore
62+
.gitmodules
63+
.gitconfig
64+
.gitattributes
65+
.svn
66+
*/.bzr/*
67+
*/.hg/*
68+
*/.svn/*
69+
70+
# Berkshelf #
71+
#############
72+
Berksfile
73+
Berksfile.lock
74+
cookbooks/*
75+
tmp
76+
77+
# Cookbooks #
78+
#############
79+
CONTRIBUTING
80+
CHANGELOG*
81+
82+
# Strainer #
83+
############
84+
Colanderfile
85+
Strainerfile
86+
.colander
87+
.strainer
88+
89+
# Vagrant #
90+
###########
91+
.vagrant
92+
Vagrantfile
93+
94+
# Travis #
95+
##########
96+
.travis.yml

files/default/config.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" standalone="yes"?>
2+
<Ec2ConfigurationSettings>
3+
<Plugins>
4+
<Plugin>
5+
<Name>Ec2SetPassword</Name>
6+
<State>Disabled</State>
7+
</Plugin>
8+
<Plugin>
9+
<Name>Ec2SetComputerName</Name>
10+
<State>Disabled</State>
11+
</Plugin>
12+
<Plugin>
13+
<Name>Ec2InitializeDrives</Name>
14+
<State>Enabled</State>
15+
</Plugin>
16+
<Plugin>
17+
<Name>Ec2EventLog</Name>
18+
<State>Disabled</State>
19+
</Plugin>
20+
<Plugin>
21+
<Name>Ec2ConfigureRDP</Name>
22+
<State>Disabled</State>
23+
</Plugin>
24+
<Plugin>
25+
<Name>Ec2OutputRDPCert</Name>
26+
<State>Enabled</State>
27+
</Plugin>
28+
<Plugin>
29+
<Name>Ec2SetDriveLetter</Name>
30+
<State>Enabled</State>
31+
</Plugin>
32+
<Plugin>
33+
<Name>Ec2WindowsActivate</Name>
34+
<State>Disabled</State>
35+
</Plugin>
36+
</Plugins>
37+
<GlobalSettings>
38+
<ManageShutdown>true</ManageShutdown>
39+
<SetDnsSuffixList>true</SetDnsSuffixList>
40+
<WaitForMetaDataAvailable>true</WaitForMetaDataAvailable>
41+
</GlobalSettings>
42+
</Ec2ConfigurationSettings>

metadata.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name "windows-hostname"
2+
maintainer "Shay Bergmann"
3+
maintainer_email "[email protected]"
4+
license "MIT"
5+
description "Sets hostname and FQDN of a windows node."
6+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7+
version "0.1.0"
8+
9+
depends "windows"
10+
11+
supports "windows"

recipes/default.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Cookbook Name:: windows-hostname
3+
# Recipe:: default
4+
#
5+
# Copyright (C) 2013 Shay Bergmann
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining
8+
# a copy of this software and associated documentation files (the
9+
# "Software"), to deal in the Software without restriction, including
10+
# without limitation the rights to use, copy, modify, merge, publish,
11+
# distribute, sublicense, and/or sell copies of the Software, and to
12+
# permit persons to whom the Software is furnished to do so, subject to
13+
# the following conditions:
14+
#
15+
# The above copyright notice and this permission notice shall be
16+
# included in all copies or substantial portions of the Software.
17+
#
18+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
#
26+
27+
require 'socket'
28+
include_recipe 'windows'
29+
30+
node[:set_fqdn] =~ /^([^.]+)\.(.+)/
31+
hostname = $1
32+
domainname = $2
33+
34+
fqdn = "#{hostname}.#{domainname}"
35+
36+
# On EC2 we have to prevent EC2 Config Service from setting the computer name on boot. Otherwise we end up
37+
# up in a nasty reboot loop...
38+
cookbook_file 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml' do
39+
source 'config.xml'
40+
only_if do
41+
File.exist? 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'
42+
end
43+
end
44+
45+
windows_batch 'change_computer_name' do
46+
ignore_failure true
47+
code <<-EOH
48+
netdom computername #{Socket.gethostname} /add:#{fqdn}
49+
netdom computername #{Socket.gethostname} /makeprimary:#{fqdn}
50+
netdom computername #{Socket.gethostname} /remove:#{Socket.gethostname}
51+
netdom computername #{Socket.gethostname} /remove:#{Socket.gethostbyname(Socket.gethostname).first}
52+
shutdown -r
53+
EOH
54+
not_if do
55+
Socket.gethostbyname(Socket.gethostname).first == "#{hostname}.#{domainname}"
56+
end
57+
end

0 commit comments

Comments
 (0)