chef-recipe

how to make chef execute with a specific user and load its environment values

放肆的年华 提交于 2019-12-23 07:30:03
问题 Hi I am creating a WCS instance, for which i have to execute the create instance command using the wcs user (webadmin), its failing to connect to DB as its not able to get the required env variables. so i put some sample code to check I am using the below code bash "wcs-create-instance" do user "webadmin" group "webspher" code <<-EOH ###{node[:websphere][:wcs][:wcs_installLocation]}/bin/config_ant.sh -DinstanceName=#{node[:websphere][:wcs][:wcs_instance]} CreateInstance whoami > /tmp/whoami

cookbook_name in recipe- TypeError: no implicit conversion of Symbol into String

心已入冬 提交于 2019-12-22 16:01:13
问题 I have the following code in my recipe but it errors. log "###" + cookbook_name + "::" + recipe_name + " " + Time.now.inspect + ": Starting execution phase" puts "###" + cookbook_name + "::" + recipe_name + " " + Time.now.inspect + ": Starting compile phase" The error is: TypeError: no implicit conversion of Symbol into String /test/chef/cookbooks/cookbook-server/recipes/setup_server.rb:10:in `+' The issue seems to be with the cookbook_name , recipe_name etc.(the ones which are not hardcoded)

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

蹲街弑〆低调 提交于 2019-12-22 08:40:11
问题 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

Why can't chef resolve my cookbooks?

梦想与她 提交于 2019-12-22 01:38:03
问题 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

chef rewind cookbook_file definition from a wrapper cookbook recipe

安稳与你 提交于 2019-12-22 01:32:26
问题 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

“include_recipe” vs. Vagrantfile “chef.add_recipe”. What's the difference?

我的梦境 提交于 2019-12-21 02:00:13
问题 Just ran nginx::source recipe on my vagrant box, and I have very unusual behaviour. When I include a recipe from the Vagrantfile (as below), everything works like a charm, chef.add_recipe("project::nginx") chef.add_recipe("nginx::source") ( project::nginx recipe is very simple. Using it to override default attributes of the nginx cookbook) but if I include a recipe at the very end of project::nginx (mentioned up), everything falls apart: node.default['nginx']['server_names_hash_bucket_size']

Chef: How do I check to see if a service is installed?

試著忘記壹切 提交于 2019-12-19 07:29:23
问题 In a recipe I want to check to see if a service is installed, and if it is not notify the 3 resources needed to install it. I tried the service resource, which correctly identifies the service when it is installed, but throws an exception if the service is not installed. I'm not sure what action to use here. :nothing just skips the resource so it ever get executed, but any of the other actions will error when they attempt to act on a service that doesn't exist. How do I detect whether a

Overriding attributes in the recipe

。_饼干妹妹 提交于 2019-12-18 10:48:09
问题 Let's say I have a default attribute in a cookbook: default.nginx_upstreams = { 'service1' => ['service1.server.com'], 'service2' => ['service2.server.com'], } Then it gets modified and overridden in roles and environments until it finally gets to my recipe. There, I compute some additional services that I would like to add to the attribute. If I do something like this: node.nginx_upstreams.merge! {'service3' => ['service3.server.com']} then when I try to use the attribute in my template, I

Chef - How Reboot VM and continue performing actions

瘦欲@ 提交于 2019-12-18 06:56:39
问题 In a Chef recipe, I need to perform a reboot on a Node after doing some actions, and after the reboot is done, I need to continue doing another actions: Recipe: -action 1 -action 2 -reboot -action3 -action4.... I have checked some existing cookbook in the community: reboot-handler, chef-reboot, chef-restart, chef-dominous, but I cannot make any of them work. Is there some method in Chef to get what I need? Please provide detailed examples. Thanks a lot for the help. 回答1: How about using chef

How to use a Ruby block to assign variables in chef recipe

ぃ、小莉子 提交于 2019-12-18 05:21:46
问题 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 block. I am having difficulty transferring variables assigned inside the block to the main code of the chef recipe. This is what I tried: ruby_block "Create list" do block do to_use ||= [] node['hosts'].each do |host| system( "#{path}/command --all" \ " | awk '{print $2; print $3}'" \ " | grep #{host} > /dev/null" ) unless $? == 0 to_use << host end end node['hosts'] = to_use