chef_gem Illformed Argument “”

Developed my cookbook on the dev server and it works great.  Try it on the UAT server in the prod environment and get chef_gem error Illformed Argument “”.  Are you kidding me?!  The code hasn’t changed at all.

It turns out that these new machines don’t have internet access for security reasons.  So, the chef_gem resource cannot download the gem generating a completely useless error message.

But, the solution is simple, or so I thought.  Just download the gem, add it as a file in the recipe and use the cookbook_file resource to download it first.

But, as it turns out, the chef_gem resource runs during compile time.  the cookbook_file resource runs at converge time. (later than compile).

Solution, force the cookbook_file resource to run at compile time.

cookbook_file “abc-gem-1.2.3.gem” do
path “/tmp/abc-gem-1.2.3.gem”
mode “0764”
action :create
end

resource(:cookbook_file => ‘abc-gem-1.2.3.gem’).run_action(:create)

chef_gem ‘abc-gem’ do
source ‘/tmp0/abc-gem-1.2.3.gem’
end

voila!

Now the chef_gem package is pulling the gem from a local file downloaded by the recipe.

Note: the chef_gem package runs at compile time so that your recipe can use in the converge whatever it installs.