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:
34
cookbooks/hostname/.kitchen.yml
Normal file
34
cookbooks/hostname/.kitchen.yml
Normal 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'
|
||||
23
cookbooks/hostname/.rubocop.yml
Normal file
23
cookbooks/hostname/.rubocop.yml
Normal 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
|
||||
13
cookbooks/hostname/Gemfile
Normal file
13
cookbooks/hostname/Gemfile
Normal 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
|
||||
20
cookbooks/hostname/LICENSE
Normal file
20
cookbooks/hostname/LICENSE
Normal 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.
|
||||
52
cookbooks/hostname/README.md
Normal file
52
cookbooks/hostname/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# hostname cookbook
|
||||
|
||||
[](https://travis-ci.org/3ofcoins/chef-cookbook-hostname)
|
||||
[](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
|
||||
15
cookbooks/hostname/Rakefile
Normal file
15
cookbooks/hostname/Rakefile
Normal 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]
|
||||
45
cookbooks/hostname/TESTING.md
Normal file
45
cookbooks/hostname/TESTING.md
Normal 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.
|
||||
41
cookbooks/hostname/Thorfile
Normal file
41
cookbooks/hostname/Thorfile
Normal 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
|
||||
7
cookbooks/hostname/attributes/default.rb
Normal file
7
cookbooks/hostname/attributes/default.rb
Normal 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
|
||||
96
cookbooks/hostname/chefignore
Normal file
96
cookbooks/hostname/chefignore
Normal 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
|
||||
44
cookbooks/hostname/metadata.json
Normal file
44
cookbooks/hostname/metadata.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "hostname",
|
||||
"description": "Configures hostname and FQDN",
|
||||
"long_description": "# hostname cookbook\n\n[](https://travis-ci.org/3ofcoins/chef-cookbook-hostname)\n[](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
|
||||
}
|
||||
20
cookbooks/hostname/metadata.rb
Normal file
20
cookbooks/hostname/metadata.rb
Normal 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)
|
||||
139
cookbooks/hostname/recipes/default.rb
Normal file
139
cookbooks/hostname/recipes/default.rb
Normal 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
|
||||
36
cookbooks/hostname/recipes/vmware.rb
Normal file
36
cookbooks/hostname/recipes/vmware.rb
Normal 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'
|
||||
Reference in New Issue
Block a user