Class: Kitchen::Provisioner::PuppetApply
- Inherits:
-
Base
- Object
- Base
- Kitchen::Provisioner::PuppetApply
- Defined in:
- lib/kitchen/provisioner/puppet_apply.rb
Overview
Puppet Apply provisioner.
Instance Attribute Summary collapse
-
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
Instance Method Summary collapse
- #calculate_path(path, type = :directory) ⇒ Object
- #cleanup_sandbox ⇒ Object
- #create_sandbox ⇒ Object
- #init_command ⇒ Object
- #install_busser ⇒ Object
- #install_command ⇒ Object
- #prepare_command ⇒ Object
- #run_command ⇒ Object
Instance Attribute Details
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
41 42 43 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 41 def tmp_dir @tmp_dir end |
Instance Method Details
#calculate_path(path, type = :directory) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 118 def calculate_path(path, type = :directory) base = config[:test_base_path] candidates = [] candidates << File.join(base, instance.suite.name, 'puppet', path) 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_sandbox ⇒ Object
242 243 244 245 246 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 242 def cleanup_sandbox return if sandbox_path.nil? debug("Cleaning up local sandbox in #{sandbox_path}") FileUtils.rmtree(sandbox_path) end |
#create_sandbox ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 225 def create_sandbox super debug("Creating local sandbox in #{sandbox_path}") yield if block_given? prepare_modules prepare_manifests prepare_files prepare_puppet_config prepare_hiera_config prepare_fileserver_config prepare_hiera_data info('Finished Preparing files for transfer') end |
#init_command ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 216 def init_command dirs = %w{modules manifests files 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 /etc/puppet/fileserver.conf;" cmd = cmd+" mkdir -p #{config[:root_path]}" debug(cmd) cmd end |
#install_busser ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 196 def install_busser if config[:require_chef_for_busser] <<-INSTALL #{Util.shell_helpers} # install chef omnibus so that busser works as this is needed to run tests :( # TODO: work out how to install enough ruby # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the # whole chef client if [ ! -d "/opt/chef" ] then echo "-----> Installing Chef Omnibus to install busser to run tests" do_download #{chef_url} /tmp/install.sh #{sudo('sh')} /tmp/install.sh fi INSTALL end end |
#install_command ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 131 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 <<-INSTALL #{Util.shell_helpers} if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then echo "-----> Installing Puppet Omnibus" do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh #{sudo('sh')} /tmp/puppet_install.sh #{version} fi #{install_busser} INSTALL else case puppet_platform when "debian", "ubuntu" info("Installing puppet on #{puppet_platform}") <<-INSTALL if [ ! $(which puppet) ]; then #{sudo('wget')} #{puppet_apt_repo} #{sudo('dpkg')} -i #{puppet_apt_repo_file} #{update_packages_debian_cmd} #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version} #{sudo('apt-get')} -y install puppet#{puppet_debian_version} fi #{install_busser} INSTALL when "redhat", "centos", "fedora" info("Installing puppet on #{puppet_platform}") <<-INSTALL if [ ! $(which puppet) ]; then #{sudo('rpm')} -ivh #{puppet_yum_repo} #{update_packages_redhat_cmd} #{sudo('yum')} -y install puppet#{puppet_redhat_version} fi #{install_busser} INSTALL else info("Installing puppet, will try to determine platform os") <<-INSTALL if [ ! $(which puppet) ]; then if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then #{sudo('rpm')} -ivh #{puppet_yum_repo} #{update_packages_redhat_cmd} #{sudo('yum')} -y install puppet#{puppet_redhat_version} else #{sudo('wget')} #{puppet_apt_repo} #{sudo('dpkg')} -i #{puppet_apt_repo_file} #{update_packages_debian_cmd} #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version} #{sudo('apt-get')} -y install puppet#{puppet_debian_version} fi fi #{install_busser} INSTALL end end end |
#prepare_command ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 248 def prepare_command commands = [] if puppet_config commands << [ sudo('cp'), File.join(config[:root_path], 'puppet.conf'), '/etc/puppet', ].join(' ') end 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 fileserver_config commands << [ sudo('cp'), File.join(config[:root_path], 'fileserver.conf'), '/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_command ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 297 def run_command if !config[:puppet_apply_command].nil? return config[:puppet_apply_command] else [ 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')}", "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}", puppet_environment_flag, puppet_noop_flag, puppet_verbose_flag, puppet_debug_flag, ].join(" ") end end |