Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

15
cookbooks/hostname/.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
*#
*.un~
*~
.#*
.*.sw[a-z]
.bundle/*
.kitchen.local.yml
.kitchen/
.vagrant
/cookbooks
Berksfile.lock
Gemfile.lock
\#*#
bin/*
metadata.json

View File

@@ -0,0 +1,57 @@
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
platforms:
- name: ubuntu-12.04
driver_config:
box: opscode_ubuntu-12.04_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04_chef-provisionerless.box
- name: ubuntu-10.04
driver_config:
box: opscode_ubuntu-10.04_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-10.04_chef-provisionerless.box
- name: debian-6
driver_config:
box: opscode_debian-6.0.8_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-6.0.8_chef-provisionerless.box
- name: debian-7
driver_config:
box: opscode_debian-7.2.0_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-7.2.0_chef-provisionerless.box
- name: centos-6.4
driver_config:
box: opscode_centos-6.4_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.4_chef-provisionerless.box
#- name: freebsd-9.2
# driver_config:
# box: opscode_freebsd-9.2_provisionerless
# box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_freebsd-9.2_chef-provisionerless.box
- name: freebsd-10
driver_config:
box: opscode_freebsd-10.0_provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_freebsd-10.0_chef-provisionerless.box
- name: fedora-19
driver_config:
box: opscode_fedora-19_chef-provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_fedora-19_chef-provisionerless.box
- name: fedora-20
driver_config:
box: opscode_fedora-20_chef-provisionerless
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_fedora-20_chef-provisionerless.box
suites:
- name: default
run_list:
- recipe[hostname::default]
attributes:
set_fqdn: test.example.com
- name: wildcard
run_list:
- recipe[hostname::default]
provisioner:
solo_rb:
node_name: test
attributes:
set_fqdn: '*.example.com'

View File

@@ -0,0 +1,9 @@
AllCops:
Excludes:
- tmp/**
Documentation:
Enabled: false
LineLength:
Enabled: false

View File

@@ -0,0 +1,13 @@
bundler_args: --without integration
before_script: bundle exec berks install
script: bundle exec strainer test
language: ruby
rvm:
- 1.9.3
notifications:
hipchat:
secure: ! 'mTePogP3SZVXbZ8l3o1yN+uszEEwQY3WgBXXXQc4hV1nLGhAXgjgj5ueCKAE
JzFSZEjp+31OOg4CIMKs+awwv/SUnFUjB1hlHPrpVnWqUORez6l2fvPABiIs
kshNJ3x5zPlxJwo/U8jObaxJ7XdjxFKugod3q2rzTsq3TlLF2WA='

View File

@@ -0,0 +1,8 @@
# -*- ruby -*-
site :opscode
metadata
group :integration do
cookbook "minitest-handler"
end

View File

@@ -0,0 +1,46 @@
# Change History
0.3.0
=====
- Fixed (and tested) FreeBSD support
- #17: added support for RedHat & CentOS (Damien Roche, Marta Paciorkowska)
- added instructions on manual testing with reboot (Marta Paciorkowska)
0.2.0
=====
- Refresh and fix tests, add Rubocop style checks (Marta Paciorkowska)
- #16: do not remove existing /etc/hosts entries on 127.0.0.1, use
configurable IP for hostname entry we need to have for ourselves
(Jean Mertz, Marta Paciorkowska)
0.1.0
=====
- Tests: chefspec, test-kitchen
- Substitute `*` in `set_fqdn` with `node.name` to allow fully
automatic FQDN setup.
0.0.6
=====
- Clean up backup files from community.opscode.com release
0.0.5
=====
- Added change log
- `metadata.rb` explicitly states cookbook name (Chulki Lee)
- New recipe `hostname::vmware` (tily)
- Use hostsfile cookbook to manipulate `/etc/hosts`, use 127.0.1.1
instead of trying to figure out own IP (Guilhem Lettron)
0.0.4
=====
- Use attribute levels when setting for Chef 11 compatibility (Alan
Wilhelm)
0.0.3
=====
- Syntax fix for compatibility with Ruby 1.9.2
0.0.2 and before
================
This is prehistory.

View File

@@ -0,0 +1,14 @@
source 'https://rubygems.org'
gem 'berkshelf'
gem 'chef', '~> 11.10'
gem 'chefspec'
gem 'foodcritic', '~> 3.0'
gem 'rake'
gem 'strainer'
gem 'rubocop'
group :integration do
gem 'test-kitchen', '~> 1.0'
gem 'kitchen-vagrant'
end

View File

@@ -0,0 +1,44 @@
# hostname cookbook
## Description
Sets hostname and FQDN of the node. The latest code is hosted at
https://github.com/3ofcoins/chef-cookbook-hostname
### Important
Setting hostname on FQDN is not (and won't be) supported. Unfortunately, using dots in the hostname can cause
[inconsistent results for any system that consumes DNS](http://serverfault.com/questions/229331/can-i-have-dots-in-a-hostname)
and [is not allowed by RFC952](http://tools.ietf.org/html/rfc952). If a user
needs additional info in their shell prompt, they can change PS1 in etc/profile
to include the FQDN together with any information they find useful (such as
the customer, the environment, etc).
## Attributes
- `node['set_fqdn']` - FQDN to set.
The asterisk character will be replaced with `node.name`. This way,
you can add this to base role:
```ruby
default_attributes :set_fqdn => '*.project-domain.com'
```
and have node set its FQDN and hostname based on its chef node name
(which is provided on `chef-client` first run's command line).
- `node['hostname_cookbook']['hostsfile_ip']` -- IP used in
`/etc/hosts` to correctly set FQDN (default: `127.0.1.1`)
## Recipes
* `hostname::default` -- will set node's FQDN to value of `set_fqdn` attribute,
and hostname to its host part (up to first dot).
* `hostname::vmware` -- sets hostname automatically using vmtoolsd.
You do not need to set `node["set_fqdn"]`.
## Author
Author: Maciej Pasternacki maciej@3ofcoins.net

View File

@@ -0,0 +1,4 @@
rubocop: rubocop $COOKBOOK
knife test: knife cookbook test $COOKBOOK
foodcritic: foodcritic --tags ~FC015 --epic-fail any $SANDBOX/$COOKBOOK
chefspec: rspec $SANDBOX/$COOKBOOK

View File

@@ -0,0 +1,46 @@
Testing
=======
Preparation
-----
$ bundle install
And then, to install all cookbooks:
$ bundle exec berks install
Local
-----
$ bundle exec strainer test
The above runs:
- rubocop
- `knife cookbook test` tests
- Food Critic lint
- Chefspec tests
Chefspec tests (the interesting part) are in `spec/`.
Integration
-----------
$ bundle exec kitchen test
See `.kitchen.yml` and `test/` directory for details.
It is important to check if the applied hostname and fqdn values remain the same
also after machine reboot. As it is impossible to reboot using kitchen, it has to
be done manually:
- run `kitchen converge` and `kitchen verify` to ensure your run is error-free,
- log in to the machine. If you're on a Debian-based system, you need to ensure
that the `/tmp` folder won't be deleted with rebooting, since that's where busser
resides. If `/tmp` is deleted, `kitchen verify` will fail after reboot even if a
manual check confirms that hostname, fqdn and dnsdomainname are correct. You can
preserve the `/tmp` folder by typing the following in your terminal:
`sudo find /etc/default/rcS -type f -exec sed -i 's/TMPTIME=0/TMPTIME=-1/g' {} \;`
- run `sudo reboot`,
- wait for the machine to reboot and run `kitchen verify` again.

View File

@@ -0,0 +1,41 @@
# -*- ruby -*-
require 'rubygems'
require 'bundler/setup'
require 'shellwords'
class Cookbook < Thor
COOKBOOK_NAME = 'hostname'
COOKBOOK_CATEGORY = 'utilities'
include Thor::Actions
desc :edit, "Edit cookbook in browser"
def edit
open "http://community.opscode.com/cookbooks/#{COOKBOOK_NAME}/edit"
end
desc :browse, "Go to cookbook's page on Opscode's community website"
def browse
open "http://community.opscode.com/cookbooks/#{COOKBOOK_NAME}/"
end
desc :upload, "Upload cookbook to Opscode's community website"
def upload
run "knife cookbook site share #{COOKBOOK_NAME} #{Shellwords.escape(COOKBOOK_CATEGORY)} -o #{Shellwords.escape(File.dirname(File.dirname(__FILE__)))}"
end
private
def open(what)
run "#{open_cmd} #{Shellwords.escape(what)}"
end
def open_cmd
@open_cmd ||= %w[open xdg-open].find do |command|
system "which #{command} >/dev/null 2>&1"
$?.success?
end
end
end

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
default['hostname_cookbook']['hostsfile_ip'] = '127.0.1.1'
default['hostname_cookbook']['hostsfile_ip_interface'] = 'lo0' if platform == 'freebsd'

View File

@@ -0,0 +1,96 @@
# Put files/directories that should be ignored in this file when uploading
# or sharing to the community site.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
Icon?
nohup.out
ehthumbs.db
Thumbs.db
# SASS #
########
.sass-cache
# EDITORS #
###########
\#*
.#*
*~
*.sw[a-z]
*.bak
REVISION
TAGS*
tmtags
*_flymake.*
*_flymake
*.tmproj
.project
.settings
mkmf.log
## COMPILED ##
##############
a.out
*.o
*.pyc
*.so
*.com
*.class
*.dll
*.exe
*/rdoc/
# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
Guardfile
Procfile
# SCM #
#######
.git
*/.git
.gitignore
.gitmodules
.gitconfig
.gitattributes
.svn
*/.bzr/*
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Cookbooks #
#############
CONTRIBUTING
CHANGELOG*
# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer
# Vagrant #
###########
.vagrant
Vagrantfile
# Travis #
##########
.travis.yml

View File

@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
name 'hostname'
maintainer 'Maciej Pasternacki'
maintainer_email 'maciej@3ofcoins.net'
license 'MIT'
description 'Configures hostname and FQDN'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.3.0'
supports 'debian'
supports 'ubuntu'
supports 'freebsd'
depends 'hostsfile'

View File

@@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
#
# Cookbook Name:: hostname
# Recipe:: default
#
# Copyright 2011, Maciej Pasternacki
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
fqdn = node['set_fqdn']
if fqdn
fqdn = fqdn.sub('*', node.name)
fqdn =~ /^([^.]+)/
hostname = Regexp.last_match[1]
case node['platform']
when 'freebsd'
directory '/etc/rc.conf.d' do
mode '0755'
end
rc_conf_lines = ["hostname=#{fqdn}\n"]
if node['hostname_cookbook']['hostsfile_ip_interface']
rc_conf_lines <<
"ifconfig_#{node['hostname_cookbook']['hostsfile_ip_interface']}_alias=\"inet #{node['hostname_cookbook']['hostsfile_ip']}/32\"\n"
service 'netif'
end
file '/etc/rc.conf.d/hostname' do
content rc_conf_lines.join
mode '0644'
notifies :reload, 'service[netif]', :immediately \
if node['hostname_cookbook']['hostsfile_ip_interface']
end
execute "hostname #{fqdn}" do
only_if { node['fqdn'] != fqdn }
notifies :reload, 'ohai[reload]', :immediately
end
when 'centos', 'redhat', 'amazon', 'scientific'
hostfile = '/etc/sysconfig/network'
ruby_block "Update #{hostfile}" do
block do
file = Chef::Util::FileEdit.new(hostfile)
file.search_file_replace_line('^HOSTNAME', "HOSTNAME=#{fqdn}")
file.write_file
end
notifies :reload, 'ohai[reload]', :immediately
end
# this is to persist the correct hostname after machine reboot
sysctl = '/etc/sysctl.conf'
ruby_block "Update #{sysctl}" do
block do
file = Chef::Util::FileEdit.new(sysctl)
file.insert_line_if_no_match("kernel.hostname=#{hostname}", \
"kernel.hostname=#{hostname}")
file.write_file
end
notifies :reload, 'ohai[reload]', :immediately
end
execute "hostname #{hostname}" do
only_if { node['hostname'] != hostname }
notifies :reload, 'ohai[reload]', :immediately
end
service 'network' do
action :restart
end
else
file '/etc/hostname' do
content "#{hostname}\n"
mode '0644'
notifies :reload, 'ohai[reload]', :immediately
end
execute "hostname #{hostname}" do
only_if { node['hostname'] != hostname }
notifies :reload, 'ohai[reload]', :immediately
end
end
hostsfile_entry 'localhost' do
ip_address '127.0.0.1'
hostname 'localhost'
action :append
end
hostsfile_entry 'set hostname' do
ip_address node['hostname_cookbook']['hostsfile_ip']
hostname fqdn
aliases [hostname]
action :create
notifies :reload, 'ohai[reload]', :immediately
end
ohai 'reload' do
action :nothing
end
else
log 'Please set the set_fqdn attribute to desired hostname' do
level :warn
end
end

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
# Cookbook Name:: hostname
# Recipe:: vmware
#
# Copyright 2011, Maciej Pasternacki
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
if node['virtualization']['system'] != 'vmware'
Chef::Log.warn('node["virtualization"]["system"] is not "vmware".')
end
unless FileTest.executable?('/usr/sbin/vmtoolsd')
Chef::Application.fatal!('/usr/sbin/vmtoolsd is not found or not executable.')
end
node.default['set_fqdn'] = Mixlib::ShellOut.new("/usr/sbin/vmtoolsd --cmd 'info-get guestinfo.hostname'").stdout.chomp
include_recipe 'hostname::default'