chef-recipe

How do I check if Chef's version mets a gem requirement from inside a recipe?

蹲街弑〆低调 提交于 2019-12-06 05:12:01
问题 Chef::Version contains the version number of the Chef gem, and I want to check that it meets the gem requirement of ~> 10.14 inside a recipe. 回答1: Alternatively, you can use Chef’s built-in version comparison mechanisms (available since at least Chef 12): Chef::VersionConstraint.new('>= 14.0.0').include? Chef::VERSION 回答2: Use Gem::Requirement and Gem::Version : Gem::Requirement.new("~> 10.14").satisfied_by?(Gem::Version.new(Chef::VERSION)) This returns a boolean value - true if Chef::VERSION

Chef client hanging on npm install at node-gyp rebuild

浪尽此生 提交于 2019-12-06 03:47:04
问题 I'm having a problem with running npm install from a chef recipe. When I run it from the command line, it finishes fine in under a minute with just a few warnings related to package.json no repository field (which should be harmless). But when I run it from chef, it hangs with the last line output back to the command line as this: * execute[npm-install-app] action run Which is this resource block in the recipe: execute "npm-install-app" do cwd "#{home}/#{prefix}#{app}" command "npm --registry

home directory is not created with adding user resource with chef

Deadly 提交于 2019-12-05 14:23:24
On a vagrant box precise64 (ubuntu 12.04) While creating a user resource with Chef, the home directory is not created: My recipe: user "myuser" do supports :manage_home => true shell "/bin/bash" home "/home/myuser" comment "Created by Chef" password "myencryptedpassword" system true provider Chef::Provider::User::Useradd action :create end When I authenticate: $ su - myuser Password: No directory, logging in with HOME=/ Update - The workaround for precise64 (Ubuntu 12.04 64bit) directory "/home/myuser" do owner "myuser" group "myuser" mode 00755 action :create end While system users usually

Why does the LWRP custom definition gives me undefined method for nil:NilClass

喜你入骨 提交于 2019-12-05 11:55:34
I have problem with my custom definition of this LWRP. resources : user_postgresql. actions :create, :alter default_action :create attribute :username, :kind_of => String attribute :password, :kind_of => String attribute :database_name, :kind_of => String providers : user_postgresql. def whyrun_supported? true end action :create do converge_by "Create [#{new_resource}]" do USER_NAME = new_resource.username USER_PASSWORD = new_resource.password unless (new_resource.password.nil? || new_resource.password.empty?) USER_PASSWORD = USER_NAME DATABASE_NAME = new_resource.database_name unless (new

chef ruby gem installer failing

那年仲夏 提交于 2019-12-05 10:51:33
I am trying to setup cassandra on an CentOS VM via chef and it fails with the error below. I have tried clearing out bundle caches to no avail. The recipe works on another machine but a key difference is that I ran other recipes on that machine beforehand so I suspect I am missing a chef dependency (which is why I haven't tried just fixing the packages directly). I am also terribly new to ruby so sorry if this is an obvious question. Machine config Chef: 11.4.0 ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux] gem 1.8.24 Linux somehost 2.6.32-276.el6.x86_64 #1 SMP Tue May 29 17:38:19

Need to refactor to the new Ruby 1.9 hash syntax [duplicate]

风格不统一 提交于 2019-12-05 08:15:39
This question already has an answer here: Hash syntax in Ruby [duplicate] 1 answer I have a recipe that has the following code that is failing a lint test: service 'apache' do supports :status => true, :restart => true, :reload => true end It fails with the error: Use the new Ruby 1.9 hash syntax. supports :status => true, :restart => true, :reload => true Not sure what the new syntax looks like... can anyone please assist? In the Ruby version 1.9 has been introduced a new syntax for hash literals whose keys are symbols. Hashes use the "hash rocket" operator to separate the key and the value:

Why can't chef resolve my cookbooks?

百般思念 提交于 2019-12-04 23:03:16
Intro I am learning Chef to automate the server management at work. I downloaded chefdk 3.0 from here and now I am trying to build my first cookbook using chef. Important I am using this in a Windows environment for testing purpose, I do expect it to fail since Windows does not have iptables, but I do not expect it to fail saying that it can't find the cookbook. I've tried using Windows cookbook and it works. The problem I am able to create the cookbook and run it, but I am not able to reference dependencies from supermarket. I have tried two alternatives: Alternative 1 I used the following

chef rewind cookbook_file definition from a wrapper cookbook recipe

佐手、 提交于 2019-12-04 21:33:01
I am using an cookbook github.com opscode-cookbooks/openldap. I wrote an wrapper cookbook "lab_openldap" that includes "openldap::server" recipe. The server.rb recipe uses following clausule to upload the PEM file from cookbooks files/ssl/*.pem to server to the location node['openldap']['ssl_cert']. if node['openldap']['tls_enabled'] && node['openldap']['manage_ssl'] cookbook_file node['openldap']['ssl_cert'] do source "ssl/#{node['openldap']['server']}.pem" mode 00644 owner "root" group "root" end end The PEM is tried to be read from "openldap" cookbook file/ssl/#{node['openldap']['server']}

How to pass Chef data bag secret to a docker container?

≡放荡痞女 提交于 2019-12-04 19:17:56
I have already created a databag item which is existing on the chef server. Now, I am trying to pass on that databag item secret value to a docker container. I am creating the data bag as follows: knife data bag create bag_secrets bag_masterkey --secret-file C:\path\data_bag_secret I am retrieving value of that databag item in Chef recipe as follows: secret = Chef::EncryptedDataBagItem.load_secret("#{node['secret']}") masterkey = Chef::EncryptedDataBagItem.load("databag_secrets", "databag_masterkey", secret) What logic do i need to add to pass on the data bag secret to a docker container? I've

Using a Chef recipe to append multiple lines to a config file

只愿长相守 提交于 2019-12-04 18:10:21
问题 I'm trying to create a Chef recipe to append multiple lines (20-30) to a specific config file. I'm aware the recommended pattern is to change entire config files rather than just appending to a file, but I dislike this approach for multiple reasons. So far the only solution I found was to use a cookbook_file and then use a bash resource to do: cat lines_to_append >> /path/configfile Obviously this wouldn't work properly, as it'd append the file over and over, each time you run chef-client. I