diff --git a/.kitchen.yml b/.kitchen.yml index e63cddd..8bda6a3 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -4,6 +4,10 @@ driver_config: require_chef_omnibus: true platforms: +- name: ubuntu-14.04 + driver_config: + box: opscode_ubuntu-14.04_provisionerless + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box - name: ubuntu-12.04 driver_config: box: opscode_ubuntu-12.04_provisionerless diff --git a/.rubocop.yml b/.rubocop.yml index 00d809d..1391b04 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - Excludes: + Exclude: - tmp/** Documentation: @@ -7,3 +7,6 @@ Documentation: LineLength: Enabled: false + +SingleSpaceBeforeFirstArg: + Enabled: false diff --git a/Berksfile b/Berksfile index f25cd60..454fbaf 100644 --- a/Berksfile +++ b/Berksfile @@ -1,5 +1,5 @@ # -*- ruby -*- -site :opscode +source "https://supermarket.getchef.com" metadata diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c53865..7985bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ # Change History -0.3.0 -===== +0.4.0 (2015-03-16) +================== + - #40: Use file resources with lazy eval and notifies to prevent network restarts from occurring on every chef run (Matt Kasa) + - Add box with Ubuntu 14.04 for kitchen tests + - #27: Update default recipe to reload only the hostname plugin instead of ohai (Jonathan Serafini) + +0.3.0 (2014-05-20) +================== - Fixed (and tested) FreeBSD support - #17: added support for RedHat & CentOS (Damien Roche, Marta Paciorkowska) - added instructions on manual testing with reboot (Marta Paciorkowska) diff --git a/Gemfile.lock b/Gemfile.lock index 1dbc4af..0b4c0c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,85 +1,81 @@ GEM remote: https://rubygems.org/ specs: - activesupport (3.2.17) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) addressable (2.3.6) - akami (1.2.1) - gyoku (>= 0.4.0) - nokogiri - ast (1.1.0) - berkshelf (2.0.14) - activesupport (~> 3.2.0) + ast (2.0.0) + berkshelf (3.1.5) addressable (~> 2.3.4) + berkshelf-api-client (~> 1.2) + buff-config (~> 1.0) + buff-extensions (~> 1.0) buff-shell_out (~> 0.1) - chozo (>= 0.6.1) - faraday (~> 0.8.0) - faraday (~> 0.8.5) - hashie (>= 2.0.2) + celluloid (~> 0.16.0.pre) + celluloid-io (~> 0.16.0.pre) + faraday (~> 0.9.0) minitar (~> 0.5.4) - rbzip2 (~> 0.2.0) + octokit (~> 3.0) retryable (~> 1.3.3) - ridley (~> 1.5.0) - solve (>= 0.5.0) - thor (~> 0.18.0) - buff-config (0.4.0) - buff-extensions (~> 0.3) - varia_model (~> 0.1) - buff-extensions (0.5.0) + ridley (~> 4.0) + solve (~> 1.1) + thor (~> 0.18) + berkshelf-api-client (1.2.0) + faraday (~> 0.9.0) + buff-config (1.0.1) + buff-extensions (~> 1.0) + varia_model (~> 0.4) + buff-extensions (1.0.0) buff-ignore (1.1.1) buff-platform (0.1.0) buff-ruby_engine (0.1.0) - buff-shell_out (0.1.1) + buff-shell_out (0.2.0) buff-ruby_engine (~> 0.1.0) - builder (3.2.2) - celluloid (0.14.1) - timers (>= 1.0.0) - celluloid-io (0.14.1) - celluloid (>= 0.14.1) - nio4r (>= 0.4.5) - chef (11.10.4) - chef-zero (~> 1.7, >= 1.7.2) + celluloid (0.16.0.pre3) + timers (~> 4.0.0) + celluloid-io (0.16.0.pre2) + celluloid (>= 0.16.0.pre) + nio4r (>= 1.0.0) + chef (11.14.2) + chef-zero (~> 2.1, >= 2.1.4) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) + ffi-yajl (~> 1.0) highline (~> 1.6, >= 1.6.9) - json (>= 1.4.4, <= 1.8.1) mime-types (~> 1.16) mixlib-authentication (~> 1.3) mixlib-cli (~> 1.4) mixlib-config (~> 2.0) mixlib-log (~> 1.3) - mixlib-shellout (~> 1.3) + mixlib-shellout (~> 1.4) net-ssh (~> 2.6) net-ssh-multi (~> 1.1) - ohai (~> 6.0) + ohai (~> 7.2) pry (~> 0.9) - puma (~> 1.6) - rest-client (>= 1.0.4, < 1.7.0) - yajl-ruby (~> 1.1) - chef-zero (1.7.3) + rest-client (>= 1.0.4, <= 1.6.7) + chef-zero (2.2) hashie (~> 2.0) json mixlib-log (~> 1.3) - moneta (< 0.7.0) rack - chefspec (3.4.0) - chef (~> 11.0) + chefspec (4.0.1) + chef (~> 11.12) fauxhai (~> 2.0) - rspec (~> 2.14) - chozo (0.6.1) - activesupport (>= 3.2.0) - hashie (>= 2.0.2) - multi_json (>= 1.3.0) + rspec (~> 3.0) coderay (1.1.0) + dep-selector-libgecode (1.0.2) + dep_selector (1.0.3) + dep-selector-libgecode (~> 1.0) + ffi (~> 1.9) diff-lcs (1.2.5) erubis (2.7.0) - faraday (0.8.9) - multipart-post (~> 1.2.0) - fauxhai (2.1.0) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) + fauxhai (2.2.0) net-ssh ohai ffi (1.9.3) + ffi-yajl (1.0.2) + ffi (~> 1.5) + libyajl2 (~> 1.0) foodcritic (3.0.3) erubis gherkin (~> 2.11.7) @@ -89,41 +85,29 @@ GEM yajl-ruby (~> 1.1.0) gherkin (2.11.8) multi_json (~> 1.3) - gssapi (1.0.3) - ffi (>= 1.0.1) - gyoku (1.1.1) - builder (>= 2.1.2) - hashie (2.0.5) + hashie (2.1.2) highline (1.6.21) - hitimes (1.2.1) - httpclient (2.3.4.1) - httpi (0.9.7) - rack - i18n (0.6.9) + hitimes (1.2.2) ipaddress (0.8.0) json (1.8.1) - kitchen-vagrant (0.14.0) + kitchen-vagrant (0.15.0) test-kitchen (~> 1.0) - little-plugger (1.1.3) - logging (1.8.2) - little-plugger (>= 1.1.3) - multi_json (>= 1.8.4) + libyajl2 (1.0.1) method_source (0.8.2) mime-types (1.25.1) minitar (0.5.4) mixlib-authentication (1.3.0) mixlib-log - mixlib-cli (1.4.0) + mixlib-cli (1.5.0) mixlib-config (2.1.0) mixlib-log (1.6.0) - mixlib-shellout (1.3.0) - moneta (0.6.0) - multi_json (1.9.2) - multipart-post (1.2.0) + mixlib-shellout (1.4.0) + multi_json (1.10.1) + multipart-post (2.0.0) net-http-persistent (2.9.4) - net-scp (1.1.2) + net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (2.8.0) + net-ssh (2.9.1) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) net-ssh-multi (1.2.0) @@ -131,110 +115,99 @@ GEM net-ssh-gateway (>= 1.2.0) nio4r (1.0.0) nokogiri (1.5.11) - nori (1.1.5) - ohai (6.20.0) + octokit (3.3.0) + sawyer (~> 0.5.3) + ohai (7.2.0) + ffi (~> 1.9) + ffi-yajl (~> 1.0) ipaddress + mime-types (~> 1.16) mixlib-cli - mixlib-config + mixlib-config (~> 2.0) mixlib-log - mixlib-shellout - systemu (~> 2.5.2) - yajl-ruby - parser (2.1.7) - ast (~> 1.1) + mixlib-shellout (~> 1.2) + systemu (~> 2.6.4) + wmi-lite (~> 1.0) + parser (2.2.0.pre.4) + ast (>= 1.1, < 3.0) slop (~> 3.4, >= 3.4.5) - polyglot (0.3.4) + polyglot (0.3.5) powerpack (0.0.9) - pry (0.9.12.6) - coderay (~> 1.0) - method_source (~> 0.8) + pry (0.10.0) + coderay (~> 1.1.0) + method_source (~> 0.8.1) slop (~> 3.4) - puma (1.6.3) - rack (~> 1.2) rack (1.5.2) rainbow (2.0.0) - rake (10.2.1) - rbzip2 (0.2.0) + rake (10.3.2) rest-client (1.6.7) mime-types (>= 1.16) retryable (1.3.5) - ridley (1.5.3) + ridley (4.0.0) addressable - buff-config (~> 0.2) - buff-extensions (~> 0.3) + buff-config (~> 1.0) + buff-extensions (~> 1.0) buff-ignore (~> 1.1) buff-shell_out (~> 0.1) - celluloid (~> 0.14.0) - celluloid-io (~> 0.14.0) + celluloid (~> 0.16.0.pre) + celluloid-io (~> 0.16.0.pre) erubis - faraday (>= 0.8.4) - hashie (>= 2.0.2) + faraday (~> 0.9.0) + hashie (>= 2.0.2, < 3.0.0) json (>= 1.7.7) mixlib-authentication (>= 1.3.0) net-http-persistent (>= 2.8) - net-ssh - nio4r (>= 0.5.0) retryable - solve (>= 0.4.4) - varia_model (~> 0.1) - winrm (~> 1.1.0) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rubocop (0.19.1) + semverse (~> 1.1) + varia_model (~> 0.4) + rspec (3.0.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-core (3.0.3) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.3) + rspec-support (~> 3.0.0) + rspec-support (3.0.3) + rubocop (0.24.1) json (>= 1.7.7, < 2) - parser (~> 2.1.7) + parser (>= 2.2.0.pre.3, < 3.0) powerpack (~> 0.0.6) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) - ruby-progressbar (1.4.2) - rubyntlm (0.1.1) - safe_yaml (1.0.1) - savon (0.9.5) - akami (~> 1.0) - builder (>= 2.1.2) - gyoku (>= 0.4.0) - httpi (~> 0.9) - nokogiri (>= 1.4.0) - nori (~> 1.0) - wasabi (~> 1.0) - slop (3.5.0) - solve (0.8.2) - strainer (3.3.0) - berkshelf (~> 2.0) + ruby-progressbar (1.5.1) + safe_yaml (1.0.3) + sawyer (0.5.4) + addressable (~> 2.3.5) + faraday (~> 0.8, < 0.10) + semverse (1.2.1) + slop (3.6.0) + solve (1.2.1) + dep_selector (~> 1.0) + semverse (~> 1.1) + strainer (3.4.0) + berkshelf (>= 2.0, < 4.0) buff-platform (~> 0.1) - systemu (2.5.2) + systemu (2.6.4) test-kitchen (1.2.1) mixlib-shellout (~> 1.2) net-scp (~> 1.1) net-ssh (~> 2.7) safe_yaml (~> 1.0) thor (~> 0.18) - thor (0.18.1) - timers (2.0.0) + thor (0.19.1) + timers (4.0.0) hitimes treetop (1.4.15) polyglot polyglot (>= 0.3.1) - uuidtools (2.1.4) - varia_model (0.3.2) - buff-extensions (~> 0.2) - hashie (>= 2.0.2) - wasabi (1.0.0) - nokogiri (>= 1.4.0) - winrm (1.1.3) - gssapi (~> 1.0.0) - httpclient (~> 2.2, >= 2.2.0.2) - logging (~> 1.6, >= 1.6.1) - nokogiri (~> 1.5) - rubyntlm (~> 0.1.1) - savon (= 0.9.5) - uuidtools (~> 2.1.2) + varia_model (0.4.0) + buff-extensions (~> 1.0) + hashie (>= 2.0.2, < 3.0.0) + wmi-lite (1.0.0) yajl-ruby (1.1.0) PLATFORMS diff --git a/Strainerfile b/Strainerfile index 23dc97f..f0aafd1 100644 --- a/Strainerfile +++ b/Strainerfile @@ -1,4 +1,4 @@ rubocop: rubocop $COOKBOOK knife test: knife cookbook test $COOKBOOK -foodcritic: foodcritic --tags ~FC015 --epic-fail any $SANDBOX/$COOKBOOK +foodcritic: foodcritic -c 11.6.0 --tags ~FC015 --epic-fail any $SANDBOX/$COOKBOOK chefspec: rspec $SANDBOX/$COOKBOOK diff --git a/metadata.rb b/metadata.rb index ea14333..cef053a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -6,7 +6,7 @@ license 'MIT' description 'Configures hostname and FQDN' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.3.0' +version '0.4.0' supports 'debian' supports 'ubuntu' diff --git a/recipes/default.rb b/recipes/default.rb index b1e23b4..ef05790 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -53,48 +53,47 @@ execute "hostname #{fqdn}" do only_if { node['fqdn'] != fqdn } - notifies :reload, 'ohai[reload]', :immediately + notifies :reload, 'ohai[reload_hostname]', :immediately end when 'centos', 'redhat', 'amazon', 'scientific' + service 'network' do + action :nothing + end 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 + file hostfile do + action :create + content lazy { + ::IO.read(hostfile).gsub(/^HOSTNAME=.*$/, "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' - 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 + file sysctl do + action :create + content lazy { + ::IO.read(sysctl) + "kernel.hostname=#{hostname}\n" + } + not_if { ::IO.read(sysctl) =~ /^kernel\.hostname=#{hostname}$/ } + 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]', :immediately + notifies :reload, 'ohai[reload_hostname]', :immediately end - service 'network' do - action :restart - end - else file '/etc/hostname' do content "#{hostname}\n" mode '0644' - notifies :reload, 'ohai[reload]', :immediately + notifies :reload, 'ohai[reload_hostname]', :immediately end execute "hostname #{hostname}" do only_if { node['hostname'] != hostname } - notifies :reload, 'ohai[reload]', :immediately + notifies :reload, 'ohai[reload_hostname]', :immediately end end @@ -109,10 +108,11 @@ hostname fqdn aliases [hostname] action :create - notifies :reload, 'ohai[reload]', :immediately + notifies :reload, 'ohai[reload_hostname]', :immediately end - ohai 'reload' do + ohai 'reload_hostname' do + plugin 'hostname' action :nothing end else diff --git a/spec/vmware_spec.rb b/spec/vmware_spec.rb index c8c7a2b..0bbc0b4 100644 --- a/spec/vmware_spec.rb +++ b/spec/vmware_spec.rb @@ -4,7 +4,4 @@ describe 'hostname::vmware' do let(:chef_run) { ChefSpec::Runner.new.converge 'hostname::vmware' } - it 'should do something' do - pending 'Your recipe examples go here.' - end end