Class: Kitchen::Provisioner::PuppetApply

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

Overview

Puppet Apply provisioner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tmp_dirObject

Returns the value of attribute tmp_dir.



33
34
35
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 33

def tmp_dir
  @tmp_dir
end

Instance Method Details

#calculate_path(path, type = :directory) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 77

def calculate_path(path, type = :directory)
  base = File.join(config[:kitchen_root], 'puppet')
  candidates = []
  candidates << File.join(base, instance.suite.name, path)
  candidates << File.join(base, path)
  candidates << File.join(Dir.pwd, path)

  candidates.find do |c|
    type == :directory ? File.directory?(c) : File.file?(c)
  end
end

#cleanup_sandboxObject



188
189
190
191
192
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 188

def cleanup_sandbox
  return if sandbox_path.nil?
  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(sandbox_path)
end

#create_sandboxObject



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 174

def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")

  yield if block_given?

  prepare_modules
  prepare_manifests
  prepare_hiera_config
  prepare_hiera_data
  info('Finished Preparing files for transfer')

end

#init_commandObject



165
166
167
168
169
170
171
172
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 165

def init_command
  dirs = %w{modules manifests hiera hiera.yaml}.
    map { |dir| File.join(config[:root_path], dir) }.join(" ")
  cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml;"
  cmd = cmd+" mkdir -p #{config[:root_path]}"
  debug(cmd)
  cmd
end

#install_busserObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 150

def install_busser
"# install chef omnibus so that busser works as this is needed to run tests :(\n# TODO: work out how to install enough ruby\n# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the\n# whole chef client\nif [ ! -d \"/opt/chef\" ]\nthen\n  echo \"-----> Installing Chef Omnibus to install busser to run tests\"\n  curl -o /tmp/install.sh \#{chef_url}\n  \#{sudo('sh')} /tmp/install.sh\nfi\n"
end

#install_commandObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 89

def install_command
  return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
  if config[:require_puppet_omnibus]
    info("Installing puppet using puppet omnibus")
    version = if !config[:puppet_version].nil?
      "-v #{config[:puppet_version]}"
    else
      ""
    end
    "    if [ ! -d \"\#{config[:puppet_omnibus_remote_path]}\" ]; then\n      echo \"-----> Installing Puppet Omnibus\"\n      curl -o /tmp/puppet_install.sh \#{config[:puppet_omnibus_url]}\n      \#{sudo('sh')} /tmp/puppet_install.sh \#{version}\n    fi\n    \#{install_busser}\n    INSTALL\n  else\n    case puppet_platform\n    when \"debian\", \"ubuntu\"\n    info(\"Installing puppet on \#{puppet_platform}\")\n    <<-INSTALL\n    if [ ! $(which puppet) ]; then\n      \#{sudo('wget')} \#{puppet_apt_repo}\n      \#{sudo('dpkg')} -i \#{puppet_apt_repo_file}\n      \#{update_packages_debian_cmd}\n      \#{sudo('apt-get')} -y install puppet\#{puppet_debian_version}\n    fi\n    \#{install_busser}\n    INSTALL\n           when \"redhat\", \"centos\", \"fedora\"\n            info(\"Installing puppet on \#{puppet_platform}\")\n    <<-INSTALL\n    if [ ! $(which puppet) ]; then\n      \#{sudo('rpm')} -ivh \#{puppet_yum_repo}\n              \#{update_packages_redhat_cmd}\n      \#{sudo('yum')} -y install puppet\#{puppet_redhat_version}\n    fi\n    \#{install_busser}\n    INSTALL\n   else\n    info(\"Installing puppet, will try to determine platform os\")\n    <<-INSTALL\n    if [ ! $(which puppet) ]; then\n      if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then\n         \#{sudo('rpm')} -ivh \#{puppet_yum_repo}\n         \#{update_packages_redhat_cmd}\n         \#{sudo('yum')} -y install puppet\#{puppet_redhat_version}\n      else\n         \#{sudo('wget')} \#{puppet_apt_repo}\n         \#{sudo('dpkg')} -i \#{puppet_apt_repo_file}\n         \#{update_packages_debian_cmd}\n         \#{sudo('apt-get')} -y install puppet\#{puppet_debian_version}\n      fi\n    fi\n    \#{install_busser}\n    INSTALL\n   end\n  end\nend\n"

#prepare_commandObject



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 194

def prepare_command
  commands = []

  if hiera_config
    commands << [
      sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/',
    ].join(' ')

    commands << [
      sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/puppet/',
    ].join(' ')
  end

  if hiera_data and hiera_data_remote_path == '/var/lib/hiera'
    commands << [
      sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
    ].join(' ')
  end

  if hiera_data and hiera_data_remote_path != '/var/lib/hiera'
    commands << [
      sudo('mkdir -p'), hiera_data_remote_path
    ].join(' ')
                commands << [
      sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
    ].join(' ')
  end

  command = commands.join(' && ')
  debug(command)
  command
end

#run_commandObject



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 227

def run_command
  [
    custom_facts,
    sudo('puppet'),
    'apply',
    File.join(config[:root_path], 'manifests', manifest),
    "--modulepath=#{File.join(config[:root_path], 'modules')}",
    "--manifestdir=#{File.join(config[:root_path], 'manifests')}",
    puppet_noop_flag,
    puppet_verbose_flag,
    puppet_debug_flag,
  ].join(" ")
end