Reputation: 37580
I want to install a Gem (kitchen-docker) into ChefDK's Gem path.
What is the best way to install this Gem via Chef itself? Is there a more clever solution than the following?
execute "chef gem install kitchen-docker" do
user "jenkins"
not_if "chef gem list | grep ^kitchen-docker"
end
Some background information: I want to use ChefDK in Jenkins on our CI server to do cookbook testing. The CI server itself should be provisioned by Chef, of course.
Upvotes: 1
Views: 6019
Reputation: 343
Run this:
chef gem install kitchen-docker
This install gen un chefdk path.
Best regards!
Upvotes: 3
Reputation: 443
This snippet worked for me to create a resource allowing me to do
chef_dk_gem "kitchen-dokken"
It's a lot hackier than I'd like but because of issues with CHEF-2288 I otherwise had a lot of troubles getting the gem into my target user, and having the env variables for GEM* setup correctly with chef-dk
action :install do
include_recipe "chef-dk"
execute "setup chefdk gem #{gem_name}" do
command "runuser #{gem_user} -c '/opt/chefdk/embedded/bin/gem install #{gem_name}'"
not_if "/opt/chefdk/embedded/bin/gem list #{gem_name} | grep #{gem_name}'", :user => gem_user
end
end
Upvotes: 0
Reputation: 37580
Apparently, in order to install a chef gem system-wide (into /opt/chefdk/
), the parameter --no-user-install
of the gem
command can be used through the gem_package
resource:
gem_package "kitchen-docker" do
gem_binary "/opt/chefdk/embedded/bin/gem"
options "--no-user-install"
end
This installs the gem and makes it available to all users running chefdk on the system.
Upvotes: 2