HomebrewUser error when Vagrant up - macos

I'm trying to create a Ubuntu machine with Vagrant and Chef Solo. So, I've created a simple Vagrantfile and a simple recipe, just to test it. But I'm facing with the following error message:
Recipe Compile Error in
/tmp/vagrant-chef/f10d707023a689f28124f5dcfaadbc2a/cookbooks/homebrew/libraries/helpers.rb
==> default: NameError
==> default: uninitialized constant Chef::Mixin::HomebrewUser
==> default: Cookbook Trace:
==> default: /tmp/vagrant-chef/f10d707023a689f28124f5dcfaadbc2a/cookbooks/homebrew/libraries/helpers.rb:23:in
<class:Chef12HomebrewUser>'<br/>
==> default: /tmp/vagrant-chef/f10d707023a689f28124f5dcfaadbc2a/cookbooks/homebrew/libraries/helpers.rb:22:in<br/>
'
==> default:
==> default: Relevant File Content:
==> default: /tmp/vagrant-chef/f10d707023a689f28124f5dcfaadbc2a/cookbooks/homebrew/libraries/helpers.rb:
==> default:
==> default: 16: # distributed under the License is distributed on an "AS IS" BASIS,
==> default: 17: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
==> default: 18: # See the License for the specific language governing permissions and
==> default: 19: # limitations under the License.
==> default: 20: #
==> default: 21:
==> default: 22: class Chef12HomebrewUser
==> default: 23>> include Chef::Mixin::HomebrewUser
==> default: 24: end
==> default: 25:
==> default: 26: module Homebrew
==> default: 27: extend self # rubocop:disable ModuleFunction
==> default: 28:
==> default: 29: def exist?
==> default: 30: Chef::Log.debug('Checking to see if the homebrew binary exists')
==> default: 31: ::File.exist?('/usr/local/bin/brew')
==> default: 32: end
==> default:
Below there are my files:
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.berkshelf.enabled = true
config.berkshelf.berksfile_path = "./cookbooks/teste/Berksfile"
config.vm.provision "chef_solo" do |chef|
chef.install = false
chef.add_recipe "teste"
end
end
Berksfile
source 'https://supermarket.chef.io'
metadata
default.rb
include_recipe 'apt::default'
include_recipe 'java::default'
attributes.rb
default['java']['install_flavor'] = 'openjdk'
default['java']['jdk_version'] = '8'
default['java']['accept_license_agreement'] = true
metadata.rb
name 'teste'
maintainer 'The Authors'
maintainer_email 'you#example.com'
license 'All Rights Reserved'
description 'Installs/Configures teste'
long_description 'Installs/Configures teste'
version '0.1.0'
chef_version '>= 12.1' if respond_to?(:chef_version)
depends 'apt'
depends 'java'
About my configuration:
Chef Development Kit Version: 2.3.4
chef-client version: 13.4.19
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.36.1
Vagrant 2.0.1
macOS Sierra (10.12.6)

I could fix that adding config.omnibus.chef_version = :latest on Vangratfile. It means Vagrant will use the latest version for chef everytime.

Related

Could not find class at /tmp/vagrant-puppet

I can't provision, i search in the other threads but no one is useful!
I'm using Vagrant with Puppet both of them at the latest version, my project structure is:
prova
|
|__Vagrantfile
|
|__puppet
|__manifests
| |__ubonda.pp
|
|__modules
|
|__apache
|
|__manifests
|
|__apache.pp
My VagrantFile is:
Vagrant.configure("2") do |config|
config.vm.define "ubonda" do |vm0|
vm0.vm.hostname = "ubonda"
vm0.vm.box = "hashicorp/precise64"
vm0.vm.provision "puppet" do |puppet|
puppet.manifests_path = 'puppet/manifests'
puppet.module_path = 'puppet/modules'
puppet.manifest_file = "ubonda.pp"
end
end
end
My ubonda.pp file is:
# default path
Exec {
path => ["/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/usr/local/sbin"]
}
include apache
My apache.pp file is:
class apache {
# install apache
package { "apache2":
ensure => present,
require => Exec["apt-get update"]
}
# ensures that mode_rewrite is loaded and modifies the default configuration file
file { "/etc/apache2/mods-enabled/rewrite.load":
ensure => link,
target => "/etc/apache2/mods-available/rewrite.load",
require => Package["apache2"]
}
# create directory
file {"/etc/apache2/sites-enabled":
ensure => directory,
recurse => true,
purge => true,
force => true,
before => File["/etc/apache2/sites-enabled/vagrant_webroot"],
require => Package["apache2"],...
}
}
If i launch vagrant provision i obtain :
==> ubonda: Running provisioner: puppet...
==> ubonda: Running Puppet with ubonda.pp...
==> ubonda: warning: Could not retrieve fact fqdn
==> ubonda: Could not find class apache for ubonda at /tmp/vagrant-puppet/manifests-846018e2aa141a5eb79a64b4015fc5f3/ubonda.pp:6 on node ubonda
I search in the tmp/manifests folder of the ubonda vm and inside there is only the ubonda.pp while in the tmp/modules there is the apache but the two are not connected, so I tried to copy inside the manifest but nothing has changed, how can I do?
The solution is very simple but I leave the question for posterity.
The file containing the puppet specifications must be named as init.pp for it to be correctly recognized

Chef: No such cookbook

I'm getting this error when I'm trying to provion my vm using vagrant and chef:
==> default: ====================================
==> default: Error Resolving Cookbooks for Run List:
==> default: ====================================
==> default:
==> default: Missing Cookbooks:
==> default: ------------------
==> default: No such cookbook: windows
==> default:
==> default: Expanded Run List:
==> default: ------------------
==> default: * java
==> default:
==> default: Platform:
==> default: ---------
==> default: x86_64-linux
==> default:
My vagrant structure is:
VagrantFile
├───chef
│ ├───cookbooks
│ │ ├───apt
│ │ ├───java
│ ├───roles
│ │ ├───java-dev-workstation.rb
Vagrantfile content is:
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provision "chef_solo" do |chef|
chef.roles_path = "chef/roles"
chef.cookbooks_path = "chef/cookbooks"
chef.add_role "java-dev-workstation"
end
end
And java-dev-workstation.rb:
name "java-dev-workstation"
default_attributes(
# Because it's Oracle, we need to agree to the terms and conditions.
:java => {
:install_flavor => 'oracle',
:jdk_version => '8',
:accept_license_agreement => true,
:oracle => { "accept_oracle_download_terms" => true }
}
)
run_list(
"recipe[java]"
)
I'm using Chef 12.18.31.
Any ideas?
The java cookbook depends on the windows cookbook, which you don't have downloaded and so it cannot proceed. This is why people generally use Berkshelf or the Policyfile system as both of those download dependencies automatically for you.
And to answer your likely next question: yes you need the dependency even though you aren't using a Windows VM, we don't have any way to do optional dependencies.
Agreed with previous comment. So not to add all the dependencies manually use vagrant-berkshelf plugin - https://github.com/berkshelf/vagrant-berkshelf
All you need to do:
Declare all the dependencies ( in your case it is only java cookbook, berkshelf will take care silently about cookbooks java cookbook depends on - windows, so on .. ) in proper Berksfile
Point a Berksfile location in your Vagrantfile

Vagrant not allowing NatNetwork on adapter 1

Vagrant is forcing network type nat on adapter 1 (eth0) even when I have the network set as natnetwork in Virutalbox.
I can set up everything through Virtualbox manually and all my VMs can communicate with each other via eth0 as desired and port forwarding works as well. I would like to get Vagrant to work the same way for easy distribution among coworkers.
It looks like others have this problem and it's not being addressed by Vagrant:
https://github.com/mitchellh/vagrant/issues/2779
Anyone know of a workaround?
Details:
$ VBoxManage list natnetworks
NetworkName: ff_mgmt
IP: 10.0.2.1
Network: 10.0.2.0/24
IPv6 Enabled: No
IPv6 Prefix: fd17:625c:f037:2::/64
DHCP Enabled: No
Enabled: Yes
Port-forwarding (ipv4)
https1:tcp:[]:4441:[10.0.2.11]:443
https2:tcp:[]:4442:[10.0.2.12]:443
https3:tcp:[]:4443:[10.0.2.13]:443
ssh1:tcp:[]:2221:[10.0.2.11]:22
ssh2:tcp:[]:2222:[10.0.2.12]:22
ssh3:tcp:[]:2223:[10.0.2.13]:22
loopback mappings (ipv4)
127.0.0.1=2
Relevant part of Vagrantfile:
boxes = [
{
:name => "ff1",
:ip => "10.0.2.11",
:ssh_port => "2221",
:https_port => "4441",
:mac => "0800270fa302",
:memory => "8192",
:cpus => "4"
},
{
:name => "ff2",
:ip => "10.0.2.12",
:ssh_port => "2222",
:https_port => "4442",
:mac => "0800270fb302",
:memory => "8192",
:cpus => "4"
},
{
:name => "ff3",
:ip => "10.0.2.13",
:ssh_port => "2223",
:https_port => "4443",
:mac => "0800270fc302",
:intnet2 => "seg5a",
:memory => "8192",
:cpus => "4"
}
]
Vagrant.configure(2) do |config|
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.box = "ff"
#config.vm.box_version = 402
config.vm.hostname = opts[:name]
config.ssh.username = 'niska'
config.ssh.private_key_path = '/home/niska/.ssh/id_rsa'
config.vm.network :private_network, ip: opts[:ip]
config.vm.network :forwarded_port, guest: 22, guest_ip: opts[:ip], host: opts[:ssh_port], id: 'ssh'
config.vm.network :forwarded_port, guest: 443, host: opts[:https_port]
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = opts[:memory]
vb.cpus = opts[:cpus]
vb.customize ["modifyvm", :id, "--nic1", "natnetwork"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--macaddress1", opts[:mac]]
#vb.customize ["modifyvm", :id, "--intnet1", "ff_mgmt"]
end
end
end
Output of vagrant up. Notice override of natnetwork. Also port forwarding picks different ports and therefore fails to connect.
$ vagrant reload ff1
==> ff1: Attempting graceful shutdown of VM...
ff1: Guest communication could not be established! This is usually because
ff1: SSH is not running, the authentication information was changed,
ff1: or some other networking issue. Vagrant will force halt, if
ff1: capable.
==> ff1: Forcing shutdown of VM...
==> ff1: Clearing any previously set network interfaces...
==> ff1: Preparing network interfaces based on configuration...
->>> ff1: Adapter 1: nat <<<--- (overrode w/ 'nat')
ff1: Adapter 2: hostonly
==> ff1: Forwarding ports...
ff1: 22 (guest) => 2221 (host) (adapter 1)
ff1: 443 (guest) => 4441 (host) (adapter 1)
==> ff1: Running 'pre-boot' VM customizations...
==> ff1: Booting VM...
==> ff1: Waiting for machine to boot. This may take a few minutes...
ff1: SSH address: 127.0.0.1:22
ff1: SSH username: niska
ff1: SSH auth method: private key
ff1: Warning: Authentication failure. Retrying...
...
Vagrant never connects
Don't set nic1 (eth0) to anything other than NAT. virtualbox requires the first interface to be NAT.
ff1: Warning: Authentication failure. Retrying...
if you change the network type of the nic to natnetwork, then vagrant can't figure out how to ssh to the machine.
if you need vagrant at first to provision, change your network settings after you finish provisioning. however; after that point, you won't be able to use vagrant.

Chef run list is empty. Chef-Zero Vagrant Provisioner

I am trying to setup my Chef-Zero provisioner to execute the run list from a nodes JSON file. This is what my Vagrantfile looks like.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-14.04_Base_image"
config.vm.hostname = "app_node"
config.omnibus.chef_version = '12.0.3'
config.vm.provision "chef_zero" do |chef|
chef.cookbooks_path = ["../kitchen/cookbooks", "../kitchen/site-cookbooks"]
chef.roles_path = "../kitchen/roles"
chef.data_bags_path = "../kitchen/data_bags"
chef.nodes_path = "../kitchen/nodes"
chef.node_name = "app_node"
end
end
When I run vagrant up, I get the following output from the chef-zero provisioner.
==> default: Running provisioner: chef_zero...
==> default: Detected Chef (latest) is already installed
Generating chef JSON and uploading...
==> default: Warning: Chef run list is empty. This may not be what you want.
==> default: Running chef-zero...
==> default: stdin: is not a tty
==> default: [2015-01-08T01:19:51+00:00] INFO: Started chef-zero at http://localhost:8889 with repository at /tmp/vagrant-chef/bec99a1a4e96279669bc5bb3140c0f2e, /tmp/vagrant-chef/2cbca02c0b5c49646d765ae1c9c0738f
==> default: One version per cookbook
==> default: data_bags at /tmp/vagrant-chef/72ac2a17a7c339d91d27a954fc49f8c3/data_bags
==> default: nodes at /tmp/vagrant-chef/83a9002a19a985bce4d26b8c9d050540/nodes
==> default: roles at /tmp/vagrant-chef/9cdb44a6dfefce6070b32ff28cb96535/roles
==> default: [2015-01-08T01:19:51+00:00] INFO: Forking chef instance to converge...
==> default: [2015-01-08T01:19:51+00:00] INFO: *** Chef 12.0.3 ***
==> default: [2015-01-08T01:19:51+00:00] INFO: Chef-client pid: 1731
==> default: [2015-01-08T01:19:57+00:00] INFO: Run List is []
==> default: [2015-01-08T01:19:57+00:00] INFO: Run List expands to []
==> default: [2015-01-08T01:19:57+00:00] INFO: Starting Chef Run for jira
==> default: [2015-01-08T01:19:57+00:00] INFO: Running start handlers
==> default: [2015-01-08T01:19:57+00:00] INFO: Start handlers complete.
==> default: [2015-01-08T01:19:59+00:00] INFO: Chef Run complete in 1.831177529 seconds
==> default: [2015-01-08T01:19:59+00:00] INFO: Skipping removal of unused files from the cache
==> default: [2015-01-08T01:19:59+00:00] INFO: Running report handlers
==> default: [2015-01-08T01:19:59+00:00] INFO: Report handlers complete
My question is why was the runlist empty? I specified the nodes directory and the node name in the chef_zero provisioner. The JSON file that specifies the run list for "app_node" exists in the nodes directory and I can see that chef is copying up all the cookbook/nodes/roles files to the server correctly.
I feel like I am missing something here. Any help would be much appreciated. If anything is unclear let me know.
Vagrant's chef_zero provisioner is actually using chef-solo -c solo.rb -j dna.json. Your configuration in nodes is not used other than mounting the directories.
You can workaround this by doing something like this (assumes that nodes/hostname.json is the same name put in config.vm.hostname):
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "chef/centos-6.6"
config.vm.hostname = "foobarhost"
VAGRANT_JSON = JSON.parse(Pathname(__FILE__).dirname.join('../../nodes', "#{config.vm.hostname}.json").read)
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["../../cookbooks", "../../site-cookbooks"]
chef.roles_path = "../../roles"
chef.data_bags_path = "../../data_bags"
chef.verbose_logging = true
chef.run_list = VAGRANT_JSON.delete('run_list') if VAGRANT_JSON['run_list']
# Add JSON Attributes
chef.json = VAGRANT_JSON
end
end
Note I just use chef_solo, as what's the point of running chef_zero when it really calls chef_solo.
You aren't specifying a run list. The directory you're talking about is where the node data is stored, not where those JSON files are gotten. Chef has no idea what you are trying to do right now.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-14.04_Base_image"
config.vm.hostname = "app_node"
config.omnibus.chef_version = '12.0.3'
config.vm.provision "chef_zero" do |chef|
chef.cookbooks_path = ["../kitchen/cookbooks", "../kitchen/site-cookbooks"]
chef.roles_path = "../kitchen/roles"
chef.data_bags_path = "../kitchen/data_bags"
chef.nodes_path = "../kitchen/nodes"
chef.node_name = "app_node"
chef.run_list = []
chef.json = {}
end
end
This should allow you to set your run list and include any JSON attributes you wanted to include with it.
http://docs.vagrantup.com/v2/provisioning/chef_common.html
Has more options you might want to consider if they meet your needs. :-)
Vagrant doesn't consult Chef about existing nodes. In order to use the Chef node file that you wrote, you'll need to tell vagrant about it. In your Vagrantfile, add this line beneath the line chef.node_name = "app_node":
chef.json = JSON.parse(File.read("../kitchen/nodes/app_node.json"))
Once you do that, Chef and Vagrant will both look for the node configuration data in the same place.
I am not sure how to specify a local directory (still researching), but when you specify this in the Vagrantfile in chef.run_list["stuff"], vagrant will put a /tmp/vagrant-chef/dna.json
It also creates a solo.rb, which will insert stuff like node_name, if chef.node_name is created.

Provisioning Vagrant with Chef role error

I'm relatively new to Chef, and I'm trying to setup a Vagrant Box using Digital Ocean as a provider and Chef as a provisioner. The issue seems to be with the roles, but as far as I can tell, they match up fine. Thanks.
Here is my Vagrantfile:
Vagrant.configure('2') do |config|
config.omnibus.chef_version = :latest
config.vm.provider :digital_ocean do |provider, override|
config.vm.hostname = 'majestic-chaos-ubuntu14.04x64'
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'digital_ocean'
provider.token = 'XXXXXXXXXXXX'
provider.image = 'Ubuntu 14.04 x64'
provider.region = 'nyc2'
provider.size = '512mb'
end
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ['../../cookbooks']
chef.roles_path = ['../../roles']
chef.add_role ("majestic-chaos-ubuntu14.04x64")
end
end
and my roles file:
name "majestic-chaos-ubuntu-14.04x64"
ssl_verify_mode :verify_peer
run_list(
"recipe[apt]",
"recipe[open-ssl]",
"recipe[build-essential]",
"recipe[chef-ruby_build]",
"recipe[nodejs-cookbook]",
"recipe[rbenv::user]",
"recipe[rbenv::vagrant]",
"recipe[zsh]",
"recipe[vim]",
"recipe[imagemagick]",
)
override_attributes(
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.1.2"],
global: "2.1.2",
gems: {
"2.1.2" => [
{ name: "bundler" }
]
}
}]
}
)
And this is the error I'm getting:
[2014-09-18T16:05:48-04:00] INFO: *** Chef 11.16.2 ***
[2014-09-18T16:05:48-04:00] INFO: Chef-client pid: 2934
[2014-09-18T16:05:51-04:00] INFO: Setting the run_list to ["role[majestic-chaos-
ubuntu14.04x64]"] from CLI options
default: [2014-09-18T16:05:51-04:00] ERROR: Role majestic-chaos-ubuntu14.04x64 (included
by 'top level') is in the runlist but does not exist. Skipping expand.
[2014-09-18T16:05:51-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-
stacktrace.out
[2014-09-18T16:05:51-04:00] ERROR: The expanded run list includes nonexistent roles:
majestic-chaos-ubuntu14.04x64
[2014-09-18T16:05:51-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process
exited unsuccessfully (exit code 1)
I had a similar problem when launching a Vagrant image where the roles file was not being picked up. The solution I found for that was that for the kitchen.yml file the roles file should be in JSON format. (The roles file listed above does not look like JSON).
As documented here: https://docs.chef.io/config_yml_kitchen.html
roles_path The relative path to the directory in which role data is located. This data must be defined as JSON.
Here are a few ruby commands to convert your .rb to JSON
require 'chef'
role = Chef::Role.new
role.from_file("./roles/useful_api_role.rb")
puts JSON.pretty_generate(role)
As a side effect, this above code will load up an rb config and you can validate that it's producing the role variables you expect.
Try using absolute paths for the roles and cookbooks:
chef.cookbooks_path = File.expand_path('../../cookbooks', __FILE__)
chef.roles_path = File.expand_path('../../roles', __FILE__)

Resources