nukemberg / vagrant-ohai

Vagrant plugin which installs a Vagrant Ohai plugin
MIT License
14 stars 14 forks source link

plugin path config value isn't initialized to an array : causes no method error #22

Open anadimisra opened 6 years ago

anadimisra commented 6 years ago

Vagrant version

Anadis-MacBook-Pro:vbox-vm anadi$ vagrant -v Vagrant 2.1.1

Host operating system

OSX High Sierra

Guest operating system

ubuntu 16.04 x86_64

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.vm.define "provisioner" do |provisioner|
    provisioner.vm.box = "ubuntu/xenial64"
    provisioner.vm.box_version = "20180509.0.0"
    provisioner.vm.box_check_update = false
    provisioner.omnibus.chef_version = :latest
    provisioner.vm.network "forwarded_port", guest: 80, host: 8989
    provisioner.vm.provider :virtualbox do |vbox|
      vbox.name = "chef-provisioned"
    end
    provisioner.vm.provision "chef_solo" do |chef|
      chef.node_name = "chef-provisioned"
      chef.cookbooks_path = "../../cookbooks"
      chef.verbose_logging = true
      chef.add_recipe "learn_chef_apache2"
    end
  end
end

Debug output

https://gist.github.com/anadimisra/a370cf4178c842ad1d261907eca637ae

Expected behavior

Vagrant Provisions an Ubuntu machine through chef with Apache HTTPD web server installed

Actual behavior

Fails with FATAL error

==> provisioner: Running chef-solo...
==> provisioner: [2018-05-15T10:40:14+00:00] FATAL: Configuration error NoMethodError: undefined method `<<' for nil:NilClass
==> provisioner: [2018-05-15T10:40:14+00:00] FATAL:   /tmp/vagrant-chef/solo.rb:24:in `from_string'
==> provisioner: [2018-05-15T10:40:14+00:00] FATAL: Aborting due to error in '/tmp/vagrant-chef/solo.rb'
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Steps to reproduce

  1. Use Vagrant with Virtualbox provider
  2. Create a simple chef provisioner
  3. run vagrant up

Generated solo.rb file from the Guest VM

node_name "chef-provisioned"
file_cache_path    "/var/chef/cache"
file_backup_path   "/var/chef/backup"
cookbook_path ["/tmp/vagrant-chef/4cf62a940e70dd6c25094e15c3d06903/cookbooks"]
log_level :info
verbose_logging true

encrypted_data_bag_secret nil

http_proxy nil
http_proxy_user nil
http_proxy_pass nil
https_proxy nil
https_proxy_user nil
https_proxy_pass nil
no_proxy nil

Chef::Config.from_file "/tmp/vagrant-chef/custom-config.rb"

and in the /tmp/vagrant-chef/custom-config.rb file

Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"

looks like the problem is in this method

      def ohai_custom_config(current_conf)
        tmp = Tempfile.new(["chef-custom-config", ".rb"])
        tmp.puts 'Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"'
        tmp.write(File.read(current_conf)) if current_conf
        tmp.close
        tmp
end

When I uninstall vagrant-ohai and run the vagrant file it works fine

ghost commented 6 years ago

I hit the problem and fixed it. Issued a pull request which is waiting on the owner of this repo. https://github.com/avishai-ish-shalom/vagrant-ohai/pull/21/files

Before: tmp.puts 'Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"'

After: tmp.puts 'ohai.plugin_path << "/etc/chef/ohai_plugins"'