FAQ Database Discussion Community


how do i include non chef resources using chefspec

chef,chefspec
i want to write chefspec for one of the recipe which has the code to create jenkins user as shown below. jenkins_user 'test1' do full_name 'test user' email '[email protected]' password 'testp' end Here "jenkins_user" is not a chef resource. how do i write a chefspec to run a unit test...

How to execute curl command in Chef recipe?

curl,chef
I have a curl command which is soap request and with headers like basic auth. I need to implement this curl in Chef recipe for automation.So that every time i execute the chef script ,i see this curl being executed too. Please advice me with a syntax for adding curl...

Force the order of recipes with Chef

chef
The situation is that the installation of the standard cookbook chef-provisioning will fail because of the fact that the Nokogiri gem will fail to compile with native extensions. This is the case for Ubuntu and CentOS. A bug for sure - now I'm trying to find a workaround. The compile...

Chef workstation is unable to find knife.rb unless in “chef-repo”

chef,knife
when I run knife node list while in /home/ec2-user it complains "WARNING: No knife configuration file found ERROR: Your private key could not be loaded from /etc/chef/client.pem Check your configuration file and ensure that your private key is readable" when I run knife node list while in /home/ec2-user/chef-repo it...

Iterating over an array attribute in Chef

ruby,chef,chef-recipe,lwrp
I am using Chef provisioning to create machines in AWS. When creating the machine, I add an attribute to it that is an array of JSON files. In the recipes I run, I want to iterate over this array and create a template file on the machine. The machine gets...

Replicating request to Chef with Python RSA

python,openssl,rsa,chef
Goal: I need a Python 3 wrapper for Chef's REST API. Because its Python-3, PyChef is out of the question. Problem: I am trying to replicate the Chef request with Python RSA. But the wrapper results in an error message: "Invalid signature for user or client 'XXX'". I approached the...

Chef-client does not work from Workstation but does work directly on the server

sql-server-2012,chef
I have a chef recipe that runs a chocolatey install for Microsoft SQL server. From my workbench when I run knife winrm [IP] 'chef-client -o "recipe[NetDevMachine::default]"' -m -x 'domain\myuser' over a node it fails with the error: 532459699 or sometimes 2022834173 or 2057043966 However if I log onto the VM...

how to use attributes values in powershell script

powershell,chef,chef-recipe,powershell-v4.0
I am using powershell_script resource in chef to create a database in sqlserver 2012 here. I have used database name as test1 hardcoded in script. Now I want to provide the database name from the attribute file. How can I get the value referenced from attribute file to the script....

Where yum_repository resource is defined?

chef,cookbook,lwrp
Probably this would be an easier one for the experts. I’m learning to write custom LWRP and hence trying to understand the one that is already written.. the yum cookbook. It can be found here: http://community.opscode.com/cookbooks/yum Question: In above cookbook, where (which file/line) is the resource yum_repository is defined? I...

Bundler installing gem that's already installed

ruby,gem,chef,bundler
I believe I'm misunderstanding the way bundler works, but from the bundle install documentation it seems to indicate bundler will use locally installed system gems. ... --system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application ... The --system...

Resolving Chef Dependencies

automation,dependencies,chef
In my lab, I am currently managing a 20 nodes cluster with Cobbler and Chef. Cobbler is used for OS provisioning and basic network settings, which is working fine as expected. I can manage several OS distributions with preseed-based NQA installation and local repo mirroring. We also successfully installed chef...

Ruby: Call parent method from internal class

ruby,chef
For example, I have something like that (Ruby 1.9.1): class Chef::Recipe::MyFancyFeature def my_action do search(:node, 'repice[common]') end end I assume that there is NOT difference as this way: class Chef class Recipe class MyFancyFeature def my_action do search(:node, 'repice[common]') end end end end and my second part of question (most...

Manage website users, vhosts and PHP-FPM pools using Chef

chef,chef-recipe
I'm looking to automate my cloud environment fairly soon using Chef so it can automatically scale instances and add them to HAProxy. One issue I'm having is with the concept of managing multiple virtualhosts and the users created with them to use in PHP-FPM pools. What I'd like to do...

enhance Vagrant Box and save as a new box - use 'vagrant package'?

vagrant,chef,virtualbox
Apologies, but chef/vagrant etc... have so many tools built around them that sometimes it is difficult to figure which one is a good fit for the problem at hand. So before getting started with the actual work, I'd like to confirm which tool to look at. I am spinning up...

Chef Windows AWS VPC

windows,amazon-web-services,chef,vpc
We got our entire infrastructure configured on AWS which consists of bunch of windows servers for Web front end, AD, DC, ADFS Proxy etc. provisioned in a Public subnet and Few DB servers configured as Private Subnet. private subnet can access the Internet by using a NAT server. Reference architecture...

Specifing environment in chef

chef
I have a java application for which the spring attribute is passed via the environment attribute as below. name "dev" description "The test environment" override_attributes({"dspring" => {"active_profile" => "dev", "jss_cert_location" => "/opt/mount1/certs/jssecacerts"}, I am looking for similar approach to define the environment for a ruby app in chef. The command...

Chef Configuration Constructs by Example

configuration,chef
I am trying to wrap my head around Chef and its many configuration constructs: So we have: Nodes Run Lists Roles Recipes Attributes Environments Cookbooks Templates and even 1 more thing not on that diagram: Data Bags This is a bit overwhelming. After reading pretty deep into the Chef docs,...

Launching Node.js app on OpsWorks

node.js,amazon-web-services,chef,aws-opsworks
I'm having trouble getting my OpsWorks custom recipe to launch my node application. I'm just starting to learn the fundamentals of Chef, so I may be missing something rather obvious. To get me started I forked a copy of AWS nodejs cookbook and made very minor changes. I was also...

Chef in local mode cookbooks only

vagrant,chef
I'm trying to setup a workflow to develop Chef cookbooks locally. We're currently using Chef Server with the provisioned nodes using chef-client. As part of the new workflow, we want to be able to start using Vagrant to test cookbooks locally to avoid incurring in the costs of testing on...

How should i use community chef cookbooks?

chef,provisioning,chef-recipe
Should i just download finished community cookbooks from supermarket, or there is some special mechanism (or package manager) for them, and i can just import them in my recipes somehow?

knife-windows is definitely installed but bootstrap still fails

chef,knife
I have definitely installed knife-windows. Chef gem list shows knife-windows but when I run bootstrap I'm told it's not installed. sudo -u user -H sh -c "cd /home/user/chef-repo/; chef gem list" sudo -u user -H sh -c "cd /home/user/chef-repo/; knife bootstrap windows winrm $VMIP -r 'role[build_server]' -x 'domain\user' -V -P...

Difference between convergence and idempotency in CHEF

chef,theory,configuration-management
What is the basic difference between convergence and idempotency in CHEF?

FATAL: NoMethodError: undefined method `unreachable_cookbook?' for nil:NilClass

chef,chef-recipe,berkshelf,berksfile
I am new to chef and started writing a simple recipe using the Users library. My Berksfile: [email protected]:~/chef-repo$ cat Berksfile site :opscode cookbook "users" and then I ran: berks install and my cookbooks: [email protected]:~/chef-repo$ ls cookbooks/ users finally my recipe: [email protected]:~/chef-repo$ cat blah-users.rb include_recipe "users" users_manage "blah-dev" do group_id 1001...

How many nodes a single opensource chef-server can handle

chef,knife
Following is the hardware configuration of chef-server (opensource) being used. 4 GB of RAM; 5 GB of free disk space in /opt; 5 GB of free disk space in /var; Chef-server version installed 11.6; How many nodes all running chef-client in daemon can this chef-server handle? Would it be possible...

how to use a recipe from a different chef cookbook

chef
For some development work, there is a requirement to temporarily include a recipe (lets say, myapp::recipe1) into a single node from a stack. I don't want to modify the original project itself for a temp solution on a single node. Any feedback on the below approach that i am planning...

Cannot find the LWRP in custom cookbook

chef,cookbook
I am building a cookbook that installs my node js files and then sets up initd scripts for them. Unfortunately I cannot call the non-default LWRP in the cookbook. Here is the error from the chef-client run: 26>> blah_node_as_service 'setting up pricing service' do 27: directory '/var/blah/blah-pricing/' 28: script 'pricing-http-server-cluster.js'...

chef-shell insufficient permissions

ruby,chef
I tried to create a directory in chef using this simple block of code ... directory "/opt/myfolder" do owner "abc" group "abc" mode "0755" action :create end ... When i execute this using "chef-client" it works. But when i execute this in chef-shell (running in client mode), I get this...

Chef: Undefined node attribute or method `<<' on `node' when trying to add

ruby,chef,chef-recipe
In my attributes file for postgresql recipe I have: default['postgresql']['pg_hba'] = { :comment => '# IPv4 local connections', :type => 'host', :db => 'all', :user => 'all', :addr => '127.0.0.1/32', :method => 'md5' } I want to my recipe automatically add my servers to pg_hga config file like this: lambda...

Emulation for ERB extention -%> for the purpose of unittests

ruby,rake,chef,erb
I need to evaluate an ERB template, and then ensure it's a valid NGINX configuration file, but vanilla ERB doesn't allow the -%> directive. How am I able to add that extension into my rakefile? I've been able to replicate the problem in irb as so: ~ $ irb irb(main):001:0>...

Chef: extending yum_package provider to check for version number in environment file

ruby,chef
I have 3 chef environments (dev, qa, prod) that all share one cookbook. The environment files contain RPM version numbers: { "name": "dev", ... "rpms": { "blah": "1.0", "blah2": "2.0" } ... } which the recipe uses: rpms = node['rpms'] env = node['name'] yum_package "blah" do version "#{rpms['blah']}-#{env}" end yum_package...

vagrant + chef setup trying to git clone into synced folder

git,vagrant,chef,chef-solo
I have a synced folder in my vagrant setup local.vm.synced_folder "../api", "/api" and I want to be able to git clone another repository into this folder like this: git "api" do destination "/api" repository "[email protected]:<user>/<repo>.git" revision "development" checkout_branch "development" action :sync end but I get an error saying: ==> local:...

How to explain that Ruby “end” invoke method

ruby,chef
When learning chefspec I have found the below code: describe 'example::default' do let(:chef_run) do ChefSpec::SoloRunner.new do |node| node.set['cookbook']['attribute'] = 'hello' end.converge(described_recipe) end end The end invoke the method converge, I am some new to ruby and chefspec, and I have googled it much time and got no answer, can someone...

Creating load balancer in AWS using Chef provisioning

amazon-web-services,chef,chef-recipe
I am trying to create a load balancer in AWS. I already have the machine created and the machine's node file is in my nodes folder. I keep getting an error asking me to enter the instance id of the machine. I thought the whole point of using chef provisioning...

Using a Ruby block to assign variables in chef recipe

ruby,chef,chef-recipe
I am trying to execute Ruby logic on the fly in a Chef recipe and believe that the best way to achieve this is with a ruby block. I am having difficulty transferring variables assigned inside the bock to the main code of the chef recipe. This is what I...

How can I tell if berkshelf is connecting to my chef server

chef,knife,berkshelf
I am attempting to use berkshelf with chef to provision a Vagrant machine. This is running on Windows 7. I installed Berkshelf as part of the Chef-DK. It reports version 3.2.3. My vagrant provisioning was failing because it cannot find some cookbooks. Here is the relevant bit of my Berksfile...

Reading a file and creating a user in Chef

ruby,chef
I have a list of IP address along with me. In front of those IP i have a username. What i am trying to do is make Chef read the file having IP and username and once it encounter the IP, it sould create a user of that name. But...

Is attr_accessor required in resource definition of chef lwrp?

chef,lwrp
I created an LWRP using chefdk and following the documentation and a few blog posts to the letter. resource actions :install default_action :install provides :foo attribute :name, :kind_of => String, :name_attribute => true provider provides :foo def whyrun_supported? true end use_inline_resources action :install do converge_by("install: #{@new_resource}") do execute "installation of:...

Chef Looping Recipes and Passing Data?

ruby,chef,chef-solo
In Chef Solo I am creating several virtual-hosts in a recipe called projects. I have three recipes which are used to compile 1 project: Recipes gunicorn::addsite nginx::addsite supervisor::addsite They only generate the needed templates. I am wondering: How can I run all three recipes in a loop to create several...

Support multiple notifies in definitions

chef
This is a followup question from Configure providers from variables, in a generic way I wrapped some providers into definitions and I was wondering how to handle the notifies. I succeeded in writing a cheap implementation where I can pass an array of arrays, similar to this: provider_definition name do...

knife ec2 to vpc node

amazon-ec2,automation,chef,knife
I am trying to launch node in EC2 VPC using chef knife ec2 server create to launch ec2 instance into VPC, But I looking a flag to specify vpc info. Anyone know how to spin up ec2 instance into vpc using knife ec2 server create ? Thanks...

chef-server SocketError: getaddrinfo: nodename nor servname provided, or not known

chef
I keep getting error after running ➜ chef knife ssh 'name:beautifulprayer' -x ubuntu WARNING: Failed to connect to beautifulprayer -- SocketError: getaddrinfo: nodename nor servname provided, or not known Not sure why. Here is info about the node: ➜ chef knife node show beautifulprayer Node Name: beautifulprayer Environment: _default FQDN:...

Chef: How to test that a node attribute is not stored on Chef Server?

rspec,chef,recipe,chefspec
After some chef zero runs (which save the node state as local .json files) I was dismayed to find this in the node files: ... "ssmtp": { "auth_username": "secret user name", "auth_password": "even-more-secret password" } The same runs on Chef Server would save the node data on the server. That's...

How do I add a recipe to a chef run list?

chef
I have a chef node that I'm attempting to add a recipe to. Currently, this node has one recipe in the run list: $ knife node show mynode Node Name: mynode Environment: _default FQDN: mynode.domain IP: 10.8.16.214 Run List: recipe[mycb::myrecipe1] Roles: Recipes: mycb::myrecipe1, ms_dotnet::ms_dotnet4, ms_dotnet::default, windows::default Platform: windows 6.3.9600 Tags:...

Chef: Uploading modified cookbook not working?

chef
I'm trying to modify and upload a cookbook to my Chef server but when I try that, it looks like the recipe inside the cookbook is not changed in Chef server. I am using a Win2K8 machine as my workstation, and I edit the learn_chef_iis-0.2.0\recipes\default.rb. I then do: knife cookbook...

Chef Knife not saving changes with editor

chef,chef-recipe,chef-solo,knife
I want to create a role with knife. So I run: > knife role create beautifulprayer ERROR: RuntimeError: Please set EDITOR environment variable No problem! Just add the editor. Afterwards: > knife role create beautifulprayer This opens the editor that I have set (subl) and goes ahead once the editor...

Chef - no resource or method named windows_http_acl

chef
I'm trying to use the windows_http_acl lwrp inside one of my cookbooks. When I try and use it, I get this error. ================================================================================ Recipe Compile Error in c:/chef/cache/cookbooks/foo/recipes/bar.rb ================================================================================ NoMethodError ------------- No resource or method named `windows_http_acl' for `Chef::Recipe "bar"' Cookbook Trace: --------------- c:/chef/cache/cookbooks/foo/recipes/bar.rb:26:in `from_file' Relevant...

How to download cookbooks from supermarked with deps?

rsa,chef,knife
I need to download some cookbooks. They have a lot of dependencies. I've machine with knife & chef installed. I want just to download public cookbooks. When i execute knife cookbook download git i get following error: ERROR: Your private key could not be loaded from /home/vagrant/.chef/vagrant.pem Check your configuration...

How to dynamically get IP address from already executed recipe in Chef

amazon-ec2,chef,chef-recipe,test-kitchen
I am a new to Chef and I am trying to test AWS cluster configuration for 2 db serves + 2 application servers using kitchen-ec2 and facing the following problem: I cannot dynamically pass ip_address_1 from recipe#1 (recipe#1 for server1 is completed) to recipe#2 (which is config recipe for server2...

The various components of Chef

bash,chef
Just getting started with chef and it looks like there are several components, which I'm finding rather confusing. They are all available for download via https://downloads.chef.io/ chef server to manage the centralized chef server chef client to manage each node chefdk to assist in development of chef chef "workstation" -...

Best practice for maintaining packages to be installed in chef

chef,recipe
I am trying to write cookbook for installing software in windows. when i use windows_package, installable is getting downloaded and installed. But post installation installable is not getting deleted. do we need to manually delete that file. Is there any best practice to do this....

variable scope in chef LWRPs

ruby,chef,lwrp
I have the following problem and I think its because I do not understand the variable scopes in Chef LWRPs. You can look at the cookbook at https://github.com/jkleinlercher/chef_problems and simply test the behaviour with kitchen. Even though I define the following very similar resources, I recognized, that the attribute 'colors'...

How to use/implement this Chef recipe?

chef,chef-recipe
I am really new with Chef, but am trying to use this Chef recipe: https://gist.github.com/kardeiz/7273938 I thought that I needed to create a new cookbook and put the recipe into default.rb, and the .erb into templates/default, but when I try to use the cookbook ("dcpromote") in chef-client, I am getting...

Fail without logging passwords in plain text

security,chef
So we have code that looks something like this: template my_template do #stuff variables({"password": data_bag["password"]}) end This code is all fine and good, until later, the template fails. When it does, it dumps everything, including the password, that was directed into the erb template. This data is automatically logged in...

Chef wrapper cookbooks only apply internal cookbook once

node.js,git,chef
I have a cookbook "blah-deploy-nodejs-from-git" cookbook that installs a nodejs codebase from GIT and calls NPM install on the directory. It has the following attributes git_repo branch destination I have then written cookbooks that wrap that cookook for inidividual sites, that need to get installed. In this particar case "blah-pricing"...

how to use shell script in not_if condition

bash,chef,recipe
I want to use shell script output to validate the resource in guard condition.I am using below code still its not working. bash "stampDisksuccess" do code <<-EOH whoami EOH user 'root' not_if {"`sudo sh /home/scripts/getStampedDisk.sh test`" == ''} end Whether script(getStampedDisk.sh) returns blank message or some data, bash resource is...

What's wrong with my Chef Configuration?

ruby,vagrant,chef,cookbook
Chef newb here - trying to setup a development box using vagrant to work with ruby on rails. I am digging through the docs, but can't seem to figure out the syntax around this error: ==> default: could not find recipe server for cookbook mysql Here's the VagrantFile/Cheffile: https://gist.github.com/tlaffoon/593077d63e3c92b3acf5 I...

change text in file with chef if exists and add if doesn't

ruby,chef
I know w/ chef you can add a line to a file if a pattern doesn't exist http://www.rubydoc.info/gems/chef/Chef/Util/FileEdit:insert_line_if_no_match and you can even update a line in a file if the pattern does exists http://www.rubydoc.info/gems/chef/Chef/Util/FileEdit:search_file_replace_line Is there a handy way to add if doesn't exist - and replace if does?...

Using a feature branch with Berkshelf

ruby,chef,berkshelf
I'm trying to use a feature branch to test some functionality in a current cookbook I am working on. Normally I would point to the master branch like so: cookbook 'elasticsearch', github: 'account-name/cookbook-elasticsearch' Is there any way to point to a feature branch? Has anyone had any success doing that...

How to 'kitchen login' with user different from root

chef,test-kitchen
our main cookbook disables root login via ssh, but we want to be able to execute kitchen login to play with the test machine (yes, we can do it with ssh machine, but I want to know if it is possible to configure test-kitchen to use a custom user). My...

Chef - unable to set vmswappiness in cookbook

chef
I'm trying to set up vm.swappiness in the sysctl.conf file. I have included sysctl in the metadb.rb file yet the chef-client run does not effect the change. Please help. This is what i have in the recipe...... node.set['sysctl']['set swappiness'] = { 'vm.swappiness' => '0' }

Chef overriding attributes from another recipe in same cookbook

chef,chef-recipe
I have a cookbook with 2 recipes. attributes/default.rb default['vpn']['crt'] = 'nocrt' The default recipe has a file resource that creates a generic crt file file 'cert' do path "/etc/vpn/#{node.default['network']['hostname']}.crt" owner 'root' group 'root' mode '0644' content node.default['vpn']['crt'] end In the second recipe client.rb, I include the default recipe, load an...

Logging Java Exceptions in Chef

java,chef,chef-solo
I am invoking a jar using chef like : execute "publish" do Chef::Log.info("About to published") command "java -jar myjar.jar" Chef::Log.info("Published") end Now in case while executing myjar, it throws an exception, the same is not visible on the console. Is there some way by which the same can be viewed...

Chef cookbook version delete, or update specific version

version,chef,knife,cookbook
I have long history of a cookbook that has a recipe of the app and is constantly modified. It got to the point where cookbook version is 226. I'm wondering how can upload files to specific cookbook version. I appreciate your help!

Chef custom attributes

attributes,chef,cookbook
I'm working on a custom Chef Cookbook and have defined a custom attribute called default["server"]["apikey"] = nil thats been defined within the cookbook in a separate attributes file that looks like this: #Default Attributes default["webhooks"]["get_response"] = "" default["webhooks"]["put_response"] = "" default["webhooks"]["post_response"] = "" default["server"]["username"] = "user" default["server"]["password"] = "123" default["server"]["apikey"]...

Syntax error on a Chef official recipe, provisioning Vagrant

vagrant,chef,chef-solo
I'm having a syntax error on an official recipe. When I tried to run this recipe from inside a vagrant box, it worked fine. I used: chef-client --local-mode --runlist [...] Now I'm trying to provision the box with chef-solo, as chef-client requires a server and keys. It should be equivalent....

How to create a dummy resource defined in another recipe without including the other recipe in test run?

unit-testing,rspec,chef,chef-recipe,chefspec
I have the following Chef recipe: # recipes/default.rb include_recipe 'my-cookbook::another_recipe' execute 'Do some stuff' do command "echo some stuff" action :run end template "my_dir/my_file.txt" do source "my_file.txt.erb" owner 'myuser' group 'mygroup' notifies :restart, resources(:service => 'my-service'), :delayed end and another recipe # recipes/another_recipe.rb service 'my-service' do start_command "my-service start" stop_command...

Conditional execution of resources

chef,condition,chain
I have the following 2 resources defined within a cookbook that makes HTTP requests. I essentially need to execute action 2 based on checking a condition from the result of action 1. If the condition from action 1 does not match I need the cookbook to sleep for a period...

Powershell_script resource throws error: “Your session has expired, please login again.”

powershell,chef,perforce
I am trying to use Chef to pull a file from Perforce, by calling p4 sync from a PowerShell script. As the title indicates, I am being plagued with this failure: "Your session has expired, please login again." From what I have gathered, it has something to do with the...

Iterating over EncryptedDataBagItem in Chef Recipe

ruby,json,chef,devops
I would like to decrypt a chef data bag item (named passwords) and store all of its attributes in a temporary JSON file which is read (and then deleted) by a node.js app. Is there a way to iterate over attributes of a data bag ITEM and get their values?...

Pass a variable from bash into chef template

ruby,chef,chef-recipe,chef-solo
In my chef recipe, I have a bash ruby block. I need some value generated from it passed to my templates. For example, the joke variable in here: bash "create opal user" do code <<-EOH joke='my funny joke' echo $joke EOH end template '/joke.txt' do source 'joke.txt.erb' variable(joke:"#{joke}") end ...

Using File::read in a provider's default.rb in Chef

ruby,chef,chef-recipe,lwrp
I am trying to create an LWRP that will call the resource that is defined within itself. My cookbook's structure is as follows: In the machine cookbook's provider, I have a code snippet as follows: require 'chef/provisioning' # driver for creating machines require '::File' def get_environment_json @@environment_template = JSON.parse(File::read(new_resource.template_path +...

How does Chef recipe get/retrieve parameters from databag?

ruby,chef,chef-recipe
I have been trying to learn Chef and trying to test a small Chef cookbook that would do dcpromo of a Windows 2008 R2 server. I don't remember exactly where I got the two files originally, but I was able to get it working. The original dcpromo_unattend.txt.erb file was: [DCINSTALL]...

Chef Client with client get/delete permissions?

chef
I'd like to create a chef client for API access that has permission to list and delete all existing and future clients. I'm using hosted chef, and am able to create a new client (call it X), and assign X permission to get/update/delete other specific clients. I can't, however, figure...

Chef Attribute set a variable in an array hash

ruby,arrays,variables,hash,chef
In a cookbook I have the following in my attributes/default.rb: default.ark.packages = [ { 'name' => 'optipng', 'url' => 'http://squirrelyjim.cloudfront.net/heroes/optipng-0.7.5.tar.gz', 'version' => '0.7.5' }, { 'name' => 'imagemagick', 'url' => 'http://squirrelyjim.cloudfront.net/heroes/ImageMagick-6.9.0-4.tar.gz', 'version' => '6.9.0-4' }, { 'name' => 'jpegoptim', 'url' => 'http://squirrelyjim.cloudfront.net/heroes/jpegoptim-1.4.1.tar.gz', 'version' => '1.4.1' } ] I then call...

How to setup a cronjob for Rails on AWS Opsworks using Chef?

ruby-on-rails,chef,aws-opsworks
I try to setup a cronjob for my Rails app on AWS Opsworks, but I am not sure how it works. There is the official documentation by AWS: http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-extend-cron.html cron "job_name" do hour "1" minute "10" weekday "6" command "cd /srv/www/myapp/current && rake task" end But I cannot figure out...

Configure providers from variables, in a generic way

ruby,chef,aws-opsworks
How can I create a recipe that will populate its attributes using the fiels from an instance of an object in a generic way? As an example, consider the following recipe: component = $auth_docker docker_image component.name do registry component.registry tag component.tag action :pull end When you have 50s of recipes...

Chef: Define same attribute with different values for different cookbooks

ruby,chef
Say I have a project to deploy with a template like: project/file.erb node['simpe_test_value'] I want to be able to write 2 different cookbooks to deploy the same project but with different value for the attributes being used in the template, like: cookbooks/test1/recipes/default.rb node.default['simple_test_value'] = 'in cookbook test 1' template "project/test.cfg"...

Write users to .htpasswd in chef recipe

ruby,chef,chef-recipe,.htpasswd,chef-solo
In a chef recipe invoked by chef-solo / vagrant I'm trying to write a .htpasswd file from an object of users. I specify the users in vagrantfile like this... chef.json = { :apache => { ... :my_users => { :john => "test", :matt => "test2" } ... My chef recipe...

Ruby: Looping and calling associative arrays (TypeError no implicit conversion of String into Integer)

ruby-on-rails,arrays,ruby,chef
So I have this piece of code: node['nginx'][0]['server_name']='black.domain.com' node['nginx'][0]['app_server']='http://10.50.0.163:8090' node['nginx'][0]['redirect_path']='/mesh' node['nginx'][1]['server_name']='red.domain.com' node['nginx'][1]['app_server']='http://10.50.0.163:8090' node['nginx'][1]['redirect_path']='/mesh' node.default['nginx'].each do |key, value| value.each do |prop| Chef::Log.info prop['app_server'] end end Like the title says it's erorring out on: 21>> Chef::Log.info prop['app_server'] My question is...

Parameterising node relationships using Chef

chef,chef-recipe
I have a group of servers that perform specific roles with dependencies between them i.e. web server -> application server -> database server I have Chef cookbooks that can build nodes with those roles. I am generating each node's hosts file using Chef and am using the hosted Chef Server....

Knife ec2: need to avoid re-boostraping of server after hostname change

amazon-ec2,centos,chef,hostname,knife
I might be doing something wrong, but here is the situation. Standalone Chef server 12.3.0. CentOS 6.3 running on AWS. During execution of knife bootstrap I am applying hostname:default recipe to change server's FQDN along with some other recipes. Everything iseems to be fine. Chef server shows newly boostrapped instance,...

How to install Chef knife-ec2 plugin on Ubuntu 14.04.1?

ruby,ubuntu,amazon-ec2,chef,ubuntu-14.04
I'm trying to install the Chef knife-ec2 plugin on Ubuntu Desktop 14.04.1 x64bit. Chefdk 0.4.0 installs successfully and I can use the knife command without any issues. I can install the knife-ec2 plugin without any errors by using the following command: /opt/chef/embedded/bin/gem install knife-ec2 However, once installed there seems to...

Combining Chef And Docker

docker,chef,iaas
I am having hard time figuring how I should combine Chef and Docker to get the best of them. Right now I am using Chef to automatically pull a docker image and create a container. But things get messy when I want to change the configuration inside the container. I...

Chef cookbook_file run script if updated

chef
Does anyone know if it is possible to make a script resource dependent on weather or not a cookbook_file was updated?

Equivalent of String.Format in a Chef/Bash Recipe

linux,chef
looking for something similar to .Net string format in a chef recipe ie. string phone = String.format("phone: {0}",_phone); I have a Chef recipe where I need to build up a command string with 30 of these params so hoping for a tidy way to build the string, in principle Im...

Install jenkins slave on Windows (AWS) gives java heap allocation error

amazon-web-services,jenkins,chef,winrm
I am using the jenkins cookbook to set up a windows slave on AWS. Locally (vagrant on virtualbox), it converges correctly, but when provisioning a new machine on aws using chef-provisioning and the fog driver, I run into the following error: ================================================================================ Error executing action `create` on resource 'jenkins_windows_slave[build-slave]' ================================================================================...

How to provide a way for Chef users to de-register their disposable Vagrant VM?

vagrant,chef
I've been wrestling with this one for a while, figured I would open it up to the stackoverflow community: I've got a setup where multiple developers can clone and spin up a Vagrant VM which will get provisioned with Chef. The VM has a hostname unique for the user, based...

knife search node platform on windows and mac

chef
I'm running chef 12, on ubuntu 14.04 When I run a knife node show -l "nodename" on a mac the platform attribute comes back with mac_os_x 10.10.3, mac_os_x 10.8.4 etc. When I run this on the windows machines they all return windows 6.1.7601. I don't see the attribute that shows...

Trying to start statsD via chef

node.js,chef,statsd
I'm trying to start statsD on ubuntu but I'm running into problems. If I start it, it works but blocks chef from continuing but it works and shows up in graphite. If however I start it like this (or using other methods to get it start in the background): (/usr/bin/node...

Can I reference multiple versions of a Chef cookbook?

chef,chef-recipe,cookbook
Is it possible to reference multiple versions of a Chef cookbook within a recipe like the following where a recipe in one cookbook (foo) references multiple versions of a recipe in another cookbook (bar) where the version variable is populated before this block? begin case version when "" include_recipe "cookbook-bar"...

Chef cleanup - nodes, environments, cookbooks, roles etc.,

chef
I recently inherited a chef environment that has quite some stale nodes and environments and lot of old cookbooks. For e.g. the AWS console shows that I have around 150 instances running, but a knife status shows 700 nodes. Normally, I use ansible, so I understand how that works to...

In a vagrant/ansible set up, who is responsible for starting servers (nodejs, rails)

vagrant,chef,ansible
Our infrastructure is getting pretty complex with many moving pieces so I'm setting up Vagrant with Ansible to spin up development environments. My question is who (Vagrant or Ansible or another tool) should be responsible for starting various such as rails s (for starting rails server) nginx nodejs (for seperate...

How can I get test kitchen run same chef recipe multiple times?

chef,test-kitchen
I have a chef recipe that I'm using for deploying an application. Each time the recipe runs it creates a new "release" (with the current timestamp) directory and deletes older "release" directories leaving only the 5 most recent "release" directories. (similar to how Capistrano's keep_releases works). To test that functionality...

How to use Chef Tracking Plugin in Jenkins

jenkins,chef,jenkins-plugins
I have a chef workstation setup on my Jenkins machine and currently use a "execute shell" in jenkins to run a shell script which runs knife bootstrap commands (for configuring nodes) .I have already installed the chef tracking plugin, but dont know how to use it for "tracking when/where/what files...

Chef Attributes, How to get the value of a specific key

chef,chef-recipe
I'm trying to manage a chef role as below. In this case the attribute node["customer"]["name"] is an array. In the recipe I need to get the value of the first element of the array node["customer"]["name"] as "foo". "customer" => { "name" => { ["foo"] => { "prod" => { "apache"...

How to call a method from a different recipe?

ruby,chef,chef-recipe
I am trying to access a method in recipe 'B' of cookbook "b" from recipe 'A' of cookbook "a". I have included the recipe 'B' in recipe 'A' using include_recipe 'cookbook::recipe'. #cookbook Flower #chef recipe 'Rose' DSL def method_to_be_called do something end #cookbook Animal #chef recipe 'Tiger' DSL include_recipe "Flower::Rose"...

Chefspec and stubbing shell_out comands

ruby,chef,chefspec
I've written a library method in my cookbook which would read the /etc/fstab file and modify it if there are certain options missing for mounts. When I try to write Chefspec tests, they all fail to returns the stubbed information, but rather read the local /etc/fstab on my computer. I'm...

Solutions to resize root partition on live mounted system

linux,chef,partitioning,mount
I'm writing a Chef recipe to automate setting up software RAID 1 on an existing system with. The basic procedure is: Clear partition table on new disk (/dev/sdb) Add new partitions, and set then to raid using parted (sdb1 for /boot and sdb2 with LVM for /) Create a degraded...

Chef conditional resource argument

ruby,chef,chef-recipe
I'm creating a user via Chef. His properties are stored in data bag: { "id": "developer", "home": "/home/developer", "shell": "/bin/zsh", "password": "s3cr3t" } The recipe is: developer = data_bag_item('users', 'developer') user developer['id'] do action :create supports :manage_home => true home developer['home'] comment developer['comment'] shell developer['shell'] password developer['password'] end The problem...

Using the AWS SDK during a chef run errors but running it outside of chef works

ruby,ssl,amazon-ec2,chef,aws-sdk
I have a helper library that AWS-SDK to pull information so it can return a list of names like so: def get_load_balancer_names self.elb_client.describe_load_balancers[:load_balancer_descriptions].map { |elb| elb[:load_balancer_name] } end when this code is run during the chef run I get this error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate...