Class: Kitchen::Provisioner::ChefBase

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/chef_base.rb

Overview

Common implementation details for Chef-related provisioners.

Author:

Direct Known Subclasses

ChefSolo, ChefZero

Instance Attribute Summary

Attributes inherited from Base

#instance

Instance Method Summary collapse

Methods inherited from Base

#[], #calculate_path, #cleanup_sandbox, #config_keys, #diagnose, #initialize, #name, #prepare_command, #run_command, #sandbox_path

Constructor Details

This class inherits a constructor from Kitchen::Provisioner::Base

Instance Method Details

#create_sandboxObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/kitchen/provisioner/chef_base.rb', line 116

def create_sandbox
  super
  prepare_json
  prepare_cache
  prepare_cookbooks
  prepare_data
  prepare_data_bags
  prepare_environments
  prepare_nodes
  prepare_roles
  prepare_clients
  prepare_secret
end

#init_commandObject



110
111
112
113
114
# File 'lib/kitchen/provisioner/chef_base.rb', line 110

def init_command
  dirs = %w{cookbooks data data_bags environments roles clients}.
    map { |dir| File.join(config[:root_path], dir) }.join(" ")
  "#{sudo('rm')} -rf #{dirs} ; mkdir -p #{config[:root_path]}"
end

#install_commandObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/kitchen/provisioner/chef_base.rb', line 79

def install_command
  return unless config[:require_chef_omnibus]

  url = config[:chef_omnibus_url]
  flag = config[:require_chef_omnibus]
  version = if flag.is_a?(String) && flag != "latest"
    "-v #{flag.downcase}"
  else
    ""
  end

  # use Bourne (/bin/sh) as Bash does not exist on all Unix flavors
  <<-INSTALL.gsub(/^ {10}/, '')
    sh -c '
    #{Util.shell_helpers}

    should_update_chef() {
      case "#{flag}" in
        true|`chef-solo -v | cut -d " " -f 2`) return 1 ;;
        latest|*) return 0 ;;
      esac
    }

    if [ ! -d "/opt/chef" ] || should_update_chef ; then
      echo "-----> Installing Chef Omnibus (#{flag})"
      do_download #{url} /tmp/install.sh
      #{sudo('sh')} /tmp/install.sh #{version}
    fi'
  INSTALL
end