chef

Vagrant requires attributes in roles.json that break existing Chef project

試著忘記壹切 提交于 2019-12-09 14:11:14
问题 I have an existing chef-solo project to which I am trying to add vagrant support. I typically use knife to cook these recipes on EC2 servers using Ubuntu 10.04 AMIs published by Canonical. Vagrant requires that I add chef_type and json_class attributes to my working roles/*.json files, like this: { "name": "memcached", "chef_type": "role", "json_class": "Chef::Role", "run_list": ["base", "memcached"] } If I don't add these to the role definition file, then I get this next error. Presumably

How to query cookbook versions on a node?

老子叫甜甜 提交于 2019-12-09 08:04:04
问题 Usage case: The DevOps team launched a node sometime ago, and my team would like to know what's the version(s) of one/several cookbook(s) being used in the run_list. Our DevOps team is firefighting so we'd like to find a way to be self-sufficient. Commands Tried: knife cookbook show COOKBOOK give all possible versions, but does not specify which one being used. knife node show NODE shows all cookbooks, but there's no version info attached. Question: Is there a command (something similar to

invoking knife in a ruby class

a 夏天 提交于 2019-12-09 07:01:56
问题 I'd like to create a nice wrapper class around knife to allow a program to run knife commands in a readable manner. I'm currently trying to use the knife.rb file in the chef gem as a guide to some success. However, I'm having an issue turning off the editor. If I run the following code: require 'chef/knife' knife = Chef::Knife.new knife.run(['client', 'create', 'new-client'], '--disable-editing') it results in the following error: NoMethodError: undefined method `merge!' for "--disable

Using Ruby 2.0 on Amazon OpsWorks

时光总嘲笑我的痴心妄想 提交于 2019-12-09 06:22:20
问题 I'd like to use Ruby 2.0 on Amazon OpsWorks, so I'm trying the following: Choose custom cookbooks and set them to my fork of https://github.com/aws/opsworks-cookbooks Update all version numbers here https://github.com/aws/opsworks-cookbooks/blob/master/ruby/attributes/ruby.rb to 2.0 values. This doesn't seem to have any effect, though. Do custom cookbooks override their built in counterparts? Does OpsWorks use the Ruby recipe from the cookbook for basic Ruby setup? The same question applies

Is there a way to use private git repository with Berkshelf

扶醉桌前 提交于 2019-12-08 19:49:46
问题 I created a cookbook named foo , and want to use with Berkshelf . I wrote like this in Berksfile : cookbook 'foo', git: 'https://bitbucket.org/ironsand/cookbook-foo.git' Then vendor the cookbook to cookbooks directory, but it failed with error like this: berks vendor cookbooks Resolving cookbook dependencies... Fetching 'foo' from https://bitbucket.org/ironsand/cookbook-foo.git (at master) Username for 'https://bitbucket.org': How can I tell ssh username and key to Berkshelf ? Of course my

Best way to rename a file with chef

混江龙づ霸主 提交于 2019-12-08 18:44:53
问题 How can I rename a file with chef? In the chef doc I found only: create create_if_missing delete touch 回答1: Use ruby_block and inside use ::File.Rename(src,dst). Chef framework doesn't have file rename (or at least didn't had until 0.10.18). Just an example: ruby_block "Rename file" do block do ::File.rename(new_resource.src,new_resource.dst) end end 回答2: Another option if you need to rename multiple files. Checks one of the resource to know if it already ran. ruby_block "Rename file" do

Windows command line tar “cannot connect to d: resolve failed” with Chef Knife

ε祈祈猫儿з 提交于 2019-12-08 14:55:49
问题 Using Windows Command line with cygwin, chef and ruby installed. When trying knife cookbook site install mysql returns the following error Begin output of tar zxvf D:/path/to/chef-repo/cookbooks/mysql.tar.gz STDOUT: STDERR: tar<child>: Cannot connect to D: resolve failed gzip: stdin: undexpected end of file tar: Child returned status 128 tar: Error is not recoverable: exiting now</code> How can I remedy this issue? I can manually unzip using tar zxvf mysql.tar.gz but this is less than ideal.

Generate a file from a string without having to create a template file in Chef?

被刻印的时光 ゝ 提交于 2019-12-08 14:35:58
问题 I currently use this code in a recipe: template "/var/django/.ssh/id_rsa" do source "id_rsa.erb" owner "django" group "django" variables :key => ssh_key mode 00600 end And here's what id_rsa.erb looks like: <%= @key %> I was wondering if I could avoid having a template, and simply produce the file from the string. Something like this perhaps: file_from_string "/var/django/.ssh/id_rsa" do source ssh_key owner "django" group "django" mode 00600 end 回答1: Use the file resource and specify the

Chef Users resource (check if exists?)

瘦欲@ 提交于 2019-12-08 10:05:23
问题 I know how to create a user resource: user "random" do supports :manage_home => true comment "Random User" uid 1234 gid "users" home "/home/random" shell "/bin/bash" password "$1$JJsvHslV$szsCjVEroftprNn4JHtDi." end But I'm unsure how to use Chef to find a list of all users on a current node. I looked at inspecting node[:users] during a chef-client run, but only node[:current_user] is available to me. Is there a way, in a Chef recipe, to ask if a regular user exists? I'm in a situation where

Add a new role to a Chef .json file with Sed

混江龙づ霸主 提交于 2019-12-08 08:55:59
问题 I have a typical .json file for Chef e.g. servername.json { "name": "myserver123", "chef_environment": "test", "run_list": [ "role[base-pkg]", "role[interesting_stuff]", "role[user_apps]" ] } What I would like to do is use a "one liner" to add a new role after the last role found in the file. Since I never know what roles or how many are in a file i thought to search for the final closing "]" bracket and add the new role above that. I tried the following: tac servername.json | sed -i '0,/\]/a