Vagrant provisioning using chef commands

264 views
Skip to first unread message

Mihael Keehl

unread,
Jan 6, 2015, 5:23:22 AM1/6/15
to vagra...@googlegroups.com
I'm having problems running 2 lines on my script file via vagrant.

These commands are:
chef-server-ctl user-create and chef-server-ctl org-create. I tried manually executing the commands on the terminal and they work. However, when I run it as a provision to a vagrant box, I get the error message:

==> chef: the ffi-yajl and yajl-ruby gems have incompatible C libyajl libs and should not be loaded in the same Ruby VM
==> chef: falling back to ffi which might work (or might not, no promises)
==> chef: ffi-yajl/json_gem is deprecated, these monkeypatches will be dropped shortly
==> chef: Response: <html>
==> chef: <head><title>502 Bad Gateway</title></head>
==> chef: <body bgcolor="white">
==> chef: <center><h1>502 Bad Gateway</h1></center>
==> chef: <hr><center>ngx_openresty/1.4.3.6</center>
==> chef: </body>
==> chef: </html>
==> chef: ERROR: bad gateway

Does anybody know how I can get through this?


Thanks,
Mihael

Seth Vargo

unread,
Jan 6, 2015, 10:03:09 AM1/6/15
to vagra...@googlegroups.com
What user are you running them as? Vagrant is not a tty, which could affect those scripts, but I don't think that's the problem. Can you share your complete vagrantfile please? Can you set the chef log-level to debug and see if there's anything interesting in that output?

Best,
Seth

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

Mihael Keehl

unread,
Jan 6, 2015, 9:57:05 PM1/6/15
to vagra...@googlegroups.com
# -*- 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 = "centos64"

  # ---Chef Server---
  config.vm.define :chef do |chef|
    chef.vm.hostname = 'server'
    chef.vm.network "public_network", ip: "10.0.1.230"
    chef.vm.provision :shell, :path => "centos6x_chefserver.sh"

    chef.vm.provider "virtualbox" do |chefvb|
      chefvb.customize ["modifyvm", :id, "--memory", "1024"]
    end
  end

end

and here is the script file:

#!/bin/bash

# This script deploys the Chef Server and copies the keys out to use in the host environment.
rpm_file_name="chef-server-core-12.0.1-1.x86_64.rpm"
rpm_web_location="https://s3.amazonaws.com/rise-chef/$rpm_file_name"

#Setup the variables for deployment.  
#Vagrant deployments in a development environment do things slightly differently

if [ -d '/vagrant' ]
then
if [ ! -f "/vagrant/$rpm_file_name" ]
then
echo "The chef server RPM has not yet been cached.  Downloading it"
curl -o "/vagrant/$rpm_file_name" $rpm_web_location
fi
rpm_location="/vagrant/$rpm_file_name"
vagrant=true
else
rpm_location="$rpm_web_location"
vagrant=false
fi

#Deploy chef server is not already deployed

if [ ! -d '/opt/opscode' ]
then
echo "Installing the Chef Server"
        # usually rpm -Uvh 
rpm -Uvh $rpm_location

#Setup the puppet master
chef-server-ctl reconfigure

else
echo "Chef already setup... Skipping setup step"
fi

# Once the Chef server is setup, copy the admin user key and validator key out

if [ ! -f '/etc/chef/admin.pem' ]
then
        #Create an administrator 
        echo "Creating the administrator account"

        chef-server-ctl user-create admin Administrator Administrator admini...@gmail.com password --filename /etc/chef/admin.pem

echo "Administrator account created"
fi

if [ ! -f  '/etc/chef/org.pem' ]
then
          #Create an organization
echo "Creating the Rise organization"

        chef-server-ctl org-create org Organization --association_user admin --filename /etc/chef/org.pem 

echo "org organization created"
fi

if [ "$vagrant" = true ]

then
if [ ! -d '/chef/chef-keys' ]
then
echo "Creating directory to copy admin keys into"
mkdir /chef/chef-keys
fi

echo "Copying private keys over to host"

cp /etc/chef/admin.pem /chef/chef-keys/
cp /etc/chef/rise.pem /chef/chef-keys/

else

echo "Chef Server is deployed.  You will want to copy these files off for your workstation"
echo "/etc/chef-server/admin.pem"
echo "/etc/chef-server/chef-validator.pem"
fi

Seth Vargo

unread,
Jan 7, 2015, 10:24:52 AM1/7/15
to vagra...@googlegroups.com
Do you know which part of that script is failing? Do you have a line number or anything? Debug output from the Chef installation?

Best,
Seth

Mihael Keehl

unread,
Jan 7, 2015, 10:47:38 AM1/7/15
to vagra...@googlegroups.com
The chef server installation and chef-server-ctl reconfigure is successful. It only gives an error when it executes the line:

chef-server-ctl user-create admin Administrator Administrator administrator@gmail.com password --filename /etc/chef/admin.pem and  chef-server-ctl org-create org Organization --association_user admin --filename /etc/chef/org.pem .

The error is:
        chef-server-ctl user-create admin Administrator Administrator administrator@gmail.com password --filename /etc/chef/admin.pem

Seth Vargo

unread,
Jan 7, 2015, 10:50:14 AM1/7/15
to vagra...@googlegroups.com
Can you run that with DEBUG on please? There should be a switch or flag you can pass to that command to make Chef give more debug output than a standard openresty failure.

Also, note that, IIRC, you need a FQDN to work with the Chef Server (it won't work with just an IP address)

Best,
Seth

Marcelito de Guzman

unread,
Jan 7, 2015, 10:52:51 AM1/7/15
to vagra...@googlegroups.com
I'm fairly new to Chef and Vagrant. How do I enable the debug feature?

I've set the hostname for the box, though.


--
You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/6fc-rBhl84M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.

Seth Vargo

unread,
Jan 7, 2015, 11:35:06 AM1/7/15
to vagra...@googlegroups.com
I don't know off hand - it would be in the Chef docs somewhere. Probably --log-level debug knowing Chef.

Marcelito de Guzman

unread,
Jan 7, 2015, 11:49:22 AM1/7/15
to vagra...@googlegroups.com
I've tried searching it, the log commands are specific to the sub services like opscode-reporting, no option for the chef-server-ctl service itself. 
Reply all
Reply to author
Forward
0 new messages