Vendor the external cookbooks

Knife-Zero doesn't include Berkshelf support, so vendoring everything in
the repo is convenient again
This commit is contained in:
Greg Karékinian
2019-10-13 19:17:42 +02:00
parent f4bfe31ac1
commit a32f34b408
1245 changed files with 100630 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
platforms:
- name: ubuntu-12.04
- name: ubuntu-14.04
- name: ubuntu-16.04
- name: debian-7.11
- name: debian-8.5
- name: centos-6.8
- name: centos-7.2
- name: freebsd-9.3
- name: freebsd-10.3
- name: fedora-21
- name: fedora-22
- name: fedora-23
- name: fedora-24
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,23 @@
AllCops:
DisplayCopNames: true
Exclude:
- tmp/**
Lint/AmbiguousBlockAssociation:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/LineLength:
Enabled: false
Style/Documentation:
Exclude:
- Thorfile
Style/PercentLiteralDelimiters:
Enabled: false
Style/SingleSpaceBeforeFirstArg:
Enabled: false

View File

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

View File

@@ -0,0 +1,20 @@
Copyright (c) 2011-2017 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.

View File

@@ -0,0 +1,52 @@
# hostname cookbook
[![Build Status](https://travis-ci.org/3ofcoins/chef-cookbook-hostname.svg?branch=master)](https://travis-ci.org/3ofcoins/chef-cookbook-hostname)
[![Chef cookbook](https://img.shields.io/cookbook/v/hostname.svg)](https://supermarket.chef.io/cookbooks/hostname)
## 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`)
- `node['hostname_cookbook']['hostsfile_aliases']` -- list of aliases used in
`/etc/hosts` for the ip set above (default: [`hostname`])
- `node['hostname_cookbook']['hostsfile_include_hostname_in_aliases']` -- whether to include the hostname
at the end of the aliases list above (default: true)
- `node['hostname_cookbook']['append_hostsfile_ip']` -- Set to `false` to
prevent an entry for the node's hostname from being appended in `/etc/hosts` (default: `true`)
## 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,15 @@
require 'foodcritic'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)
FoodCritic::Rake::LintTask.new do |t|
t.options = {
fail_tags: ['any']
}
end
RSpec::Core::RakeTask.new(:spec)
task default: %w[foodcritic rubocop spec]

View File

@@ -0,0 +1,45 @@
Testing
=======
Preparation
-----
$ bundle install
And then, to install all cookbooks:
$ bundle exec berks install
Local
-----
$ bundle exec rake
The above runs:
- rubocop lint
- Foodcritic 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'.freeze
COOKBOOK_CATEGORY = 'utilities'.freeze
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"
$CHILD_STATUS.success?
end
end
end

View File

@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
default['hostname_cookbook']['hostsfile_ip'] = '127.0.1.1'
default['hostname_cookbook']['hostsfile_ip_interface'] = 'lo0' if node['platform'] == 'freebsd'
default['hostname_cookbook']['hostsfile_aliases'] = []
default['hostname_cookbook']['hostsfile_include_hostname_in_aliases'] = true
default['hostname_cookbook']['append_hostsfile_ip'] = true

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,44 @@
{
"name": "hostname",
"description": "Configures hostname and FQDN",
"long_description": "# hostname cookbook\n\n[![Build Status](https://travis-ci.org/3ofcoins/chef-cookbook-hostname.svg?branch=master)](https://travis-ci.org/3ofcoins/chef-cookbook-hostname)\n[![Chef cookbook](https://img.shields.io/cookbook/v/hostname.svg)](https://supermarket.chef.io/cookbooks/hostname)\n## Description\n\nSets hostname and FQDN of the node. The latest code is hosted at\nhttps://github.com/3ofcoins/chef-cookbook-hostname\n\n### Important\n\nSetting hostname on FQDN is not (and won't be) supported. Unfortunately, using dots in the hostname can cause\n[inconsistent results for any system that consumes DNS](http://serverfault.com/questions/229331/can-i-have-dots-in-a-hostname)\nand [is not allowed by RFC952](http://tools.ietf.org/html/rfc952). If a user\nneeds additional info in their shell prompt, they can change PS1 in etc/profile\nto include the FQDN together with any information they find useful (such as\nthe customer, the environment, etc).\n\n## Attributes\n\n- `node['set_fqdn']` - FQDN to set.\n\nThe asterisk character will be replaced with `node.name`. This way,\nyou can add this to base role:\n\n```ruby\ndefault_attributes :set_fqdn => '*.project-domain.com'\n```\n\nand have node set its FQDN and hostname based on its chef node name\n(which is provided on `chef-client` first run's command line).\n\n- `node['hostname_cookbook']['hostsfile_ip']` -- IP used in\n `/etc/hosts` to correctly set FQDN (default: `127.0.1.1`)\n- `node['hostname_cookbook']['hostsfile_aliases']` -- list of aliases used in\n `/etc/hosts` for the ip set above (default: [`hostname`])\n- `node['hostname_cookbook']['hostsfile_include_hostname_in_aliases']` -- whether to include the hostname\n at the end of the aliases list above (default: true)\n\n- `node['hostname_cookbook']['append_hostsfile_ip']` -- Set to `false` to\n prevent an entry for the node's hostname from being appended in `/etc/hosts` (default: `true`)\n\n## Recipes\n\n* `hostname::default` -- will set node's FQDN to value of `set_fqdn` attribute,\nand hostname to its host part (up to first dot).\n* `hostname::vmware` -- sets hostname automatically using vmtoolsd.\nYou do not need to set `node[\"set_fqdn\"]`.\n\n## Author\n\nAuthor: Maciej Pasternacki maciej@3ofcoins.net\n",
"maintainer": "Maciej Pasternacki",
"maintainer_email": "maciej@3ofcoins.net",
"license": "MIT",
"platforms": {
"debian": ">= 0.0.0",
"ubuntu": ">= 0.0.0",
"freebsd": ">= 0.0.0"
},
"dependencies": {
"hostsfile": ">= 0.0.0"
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
},
"version": "0.4.2",
"source_url": "https://github.com/3ofcoins/chef-cookbook-hostname",
"issues_url": "https://github.com/3ofcoins/chef-cookbook-hostname/issues",
"privacy": false
}

View File

@@ -0,0 +1,20 @@
# -*- 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.4.2'
supports 'debian'
supports 'ubuntu'
supports 'freebsd'
depends 'hostsfile'
source_url 'https://github.com/3ofcoins/chef-cookbook-hostname' if respond_to?(:source_url)
issues_url 'https://github.com/3ofcoins/chef-cookbook-hostname/issues' if respond_to?(:issues_url)
chef_version '>= 12.1' if respond_to?(:chef_version)

View File

@@ -0,0 +1,139 @@
# -*- 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]
aliases = node['hostname_cookbook']['hostsfile_aliases']
aliases += [hostname] if node['hostname_cookbook']['hostsfile_include_hostname_in_aliases']
case node['platform_family']
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_hostname]', :immediately
end
when 'rhel'
service 'network' do
action :nothing
end
hostfile = '/etc/sysconfig/network'
file hostfile do
action :create
content lazy {
::IO.read(hostfile).gsub(/^HOSTNAME=.*$/, "HOSTNAME=#{fqdn}")
}
not_if { ::IO.read(hostfile) =~ /^HOSTNAME=#{fqdn}$/ }
notifies :reload, 'ohai[reload_hostname]', :immediately
notifies :restart, 'service[network]', :delayed
end
# this is to persist the correct hostname after machine reboot
sysctl = '/etc/sysctl.conf'
file sysctl do
action :create
regex = /^kernel\.hostname=.*/
newline = "kernel.hostname=#{hostname}"
content lazy {
original = ::IO.read(sysctl)
original.match(regex) ? original.gsub(regex, newline) : original + newline
}
not_if { ::IO.read(sysctl).scan(regex).last == newline }
notifies :reload, 'ohai[reload_hostname]', :immediately
notifies :restart, 'service[network]', :delayed
end
execute "hostname #{hostname}" do
only_if { node['hostname'] != hostname }
notifies :reload, 'ohai[reload_hostname]', :immediately
end
# update /etc/hostname in RHEL7+
file '/etc/hostname' do
content "#{hostname}\n"
mode '0644'
only_if { ::File.exist?('/etc/hostname') }
notifies :reload, 'ohai[reload_hostname]', :immediately
end
else
file '/etc/hostname' do
content "#{hostname}\n"
mode '0644'
notifies :reload, 'ohai[reload_hostname]', :immediately
end
execute "hostname #{hostname}" do
only_if { node['hostname'] != hostname }
notifies :reload, 'ohai[reload_hostname]', :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 aliases
unique true
action :create
notifies :reload, 'ohai[reload_hostname]', :immediately
only_if { node['hostname_cookbook']['append_hostsfile_ip'] }
end
ohai 'reload_hostname' do
plugin 'hostname'
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'