chef

How do I check if a folder exists in Chef?

扶醉桌前 提交于 2019-12-02 23:31:44
This is my code: if !::File.exist?("#{node['iis']['home']}\\backup\\BkpB4Chef") windows_batch "Backup IIS Config" do code <<-EOH "#{node['iis']['home']}"\\appcmd add backup BkpB4Chef EOH end end It always says file exists and executes the loop. sethvargo You should use Chef guards here. Guards specify conditional execution, but still insert the resource into the resource collection. In your example and jtblin answer, the resource is never added to the collection (which I'll explain a bit further in a moment). Here's some working code to get you started: windows_batch "Backup IIS Config" do

Chef attributes versus data bags

£可爱£侵袭症+ 提交于 2019-12-02 22:23:09
I'm new to Chef, and after reading the documentation I'm still having trouble understanding when to use Attributes and when to use Data bags. What kind of data should be stored as attributes, and what kind of data should be stored in data bags ? Thanks Well, it depends. Although data bags and attributes both hold data, the major difference between them is that attributes are exposed as node properties when recipe is run, but you don't have any clear overview what data bags were used (Except that you go through the recipes in run list). What I personally store in attributes are: Paths where

Importing Mysql database using Ruby/Chef Recipe for Vagrant

▼魔方 西西 提交于 2019-12-02 21:12:43
I am writing a chef script to automate setting dev environments. I can get a database created and grant privileges but I am trying to find out a way to import a mysql dump file into the database that has just been created. My code for granting the access is ruby_block "Execute grants" do block do require 'rubygems' Gem.clear_paths require 'mysql' m = Mysql.new('localhost', "root", node[:mysql][:server_root_password]) m.query("GRANT ALL ON *.* TO 'root'@'10.0.0.1' IDENTIFIED BY '#{node[:mysql][:server_root_password]}'") m.query('FLUSH PRIVILEGES') end end and I was hoping I would be able to do

How to precompile assets with Chef?

隐身守侯 提交于 2019-12-02 19:29:57
OpsWorks isn't precompiling assets on deploy. I found this recipe in this thread but I think it's not complete though, or missing something because I get an error about release_path not being found. precompile.rb: Chef::Log.info("Running deploy/before_migrate.rb...") Chef::Log.info("Symlinking #{release_path}/public/assets to #{new_resource.deploy_to}/shared/assets") link "#{release_path}/public/assets" do to "#{new_resource.deploy_to}/shared/assets" end rails_env = new_resource.environment["RAILS_ENV"] Chef::Log.info("Precompiling assets for RAILS_ENV=#{rails_env}...") execute "rake assets

chef deployment?

耗尽温柔 提交于 2019-12-02 18:51:11
I'm interested in switching from Capistrano to Chef, but am having a few issues putting all the pieces together. I've followed http://wiki.opscode.com/display/chef/Quick+Start and am able to start EC2 instances with knife . As far as code deployment, it looks as though I want to be doing what's in http://wiki.opscode.com/display/chef/Deploy+Resource , the only problem is, nowhere on that page does it mention in what directory/file the deploy /to/path code block should go. Another issue I'm having is understanding how to deploy code changes after the server has been set up. Perhaps I'm just

node search is giving nothing in test kitchen

霸气de小男生 提交于 2019-12-02 18:42:47
问题 No output from search in test kitchen Throwing error check the recipe and suggest me some details Node JSON file { "id": "cldb", "chef_type": "node", "json_class": "Chef::Node", "run_list": [], "automatic": { "hostname": "cldb.net", "fqdn":"127.0.0.1", "name": "cldb.net", "ipaddress": "127.0.0.1", "roles": [], "cldb" : true } } Recipe cldbNodes = search(:node, "cldb:true") cldb = "#{cldbNodes["fqdn"]}" file '/tmp/test.txt' do content "#{cldb}" end 回答1: To summarize from the comments above,

Replacing a template in a wrapper cookbook

眉间皱痕 提交于 2019-12-02 18:38:50
I'm trying to write a wrapper cookbook for the chef graphite repo In the recipe carbon.rb, the following lines occur: template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do owner node['apache']['user'] group node['apache']['group'] end where in templates/default/storage-schemas.conf there is a storage-schemas.conf file that is not to my liking. I can edit the file inline and achieve what I want, but it doesn't seem like a good chef practice if I want to be able to keep my repo up to date without merge conflicts. So I was wondering if I could solve this with a wrapper cookbook.

Chef clients and validators

不羁的心 提交于 2019-12-02 18:23:25
I'm trying to understand the concept of Chef clients and validators, and their relationship to the bootstrapping process. According to this article , the chef-client will use the /etc/chef/validation.pem private key to authenticate itself for the initial run, because /etc/chef/client.pem doesn't exist yet. This initial run will, somehow, produce that client.pem , which is then used for all subsequent client requests. My questions: What process places the /etc/chef/validation.pem file on the chef-client node in the first place? The bootstrap? Can someone provide an example of a knife command

Specifying which cookbooks to run with Chef Solo

耗尽温柔 提交于 2019-12-02 17:38:36
I'm using chef-solo to test my cookbooks locally, but I want to be able to only run the cookbook(s) that I'm testing. Currently, it seems like chef-solo will run all cookbooks in the cookbooks directory specified in solo.rb. I've specified the run list in the json attributes file and specified the location of the json file in solo.rb, but that doesn't seem to help. It at least parses the attributes for all the other cookbooks, because I have one that doesn't work for my local configuration and it fails the entire run. The best solution I've found so far is to move the cookbook(s) I need for

Chef: Why are resources in an “include_recipe” step being skipped?

ぐ巨炮叔叔 提交于 2019-12-02 17:33:01
Chef seems to be processing resources in a strange order, causing my build to fail. My main recipe ( mytardis-chef/site-cookbooks/recipes/default.rb ) starts like this: include_recipe "build-essential" include_recipe "mytardis::deps" include_recipe "mytardis::nginx" include_recipe "mytardis::postgresql" mytardis-chef/cookbooks/build-essential/recipes/default.rb looks like this: case node['platform'] when "ubuntu","debian" %w{build-essential binutils-doc}.each do |pkg| package pkg do action :install end end when "centos","redhat","fedora","scientific" %w{gcc gcc-c++ kernel-devel make}.each do