chef-recipe

Notify service defined in included LWRP recipe

有些话、适合烂在心里 提交于 2019-12-04 11:21:17
Is there a way to notify a service to restart which is defined by an included LWRP? I wrote an LWRP called "sidekiq" which sets up a service, like this, and appears to be working fine on its own. service "#{new_resource.name}_sidekiq" do provider Chef::Provider::Service::Upstart action [ :enable ] subscribes :restart, "template[/etc/init/#{new_resource.name}_sidekiq.conf]", :immediately end The problem is I am using it another recipe which I use for deployments, and need it to notify the service defined in the LWRP. I currently have something this include_recipe "sidekiq" deploy_revision my

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

拜拜、爱过 提交于 2019-12-04 09:24:16
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. 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 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 satisfies ~> 10.14 . 来源: https://stackoverflow.com/questions/19516077/how-do-i-check-if-chefs-version-mets-a-gem

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

▼魔方 西西 提交于 2019-12-03 11:33:17
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'd have to create a small bash script to check for a specific string first, and, if not found , append

How to query cookbook versions on a node?

橙三吉。 提交于 2019-12-03 10:18:44
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 knife search , ohai ) to query the chef-server for the versions deployed on the node? Tejay Cardon If you

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

孤街浪徒 提交于 2019-12-03 07:35:17
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'] = 128 include_recipe "nginx::source" Until now I didn't know there's any difference in behaviour

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,

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

风流意气都作罢 提交于 2019-12-02 10:26:55
问题 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 { if Chef::Config[:solo] return (Array.new.push node) end search(:node, "recipes:my_server AND chef_environment:#{node.chef_environment} ") }.call.each do |server_node| node['postgresql'][

node search is giving nothing in test kitchen

﹥>﹥吖頭↗ 提交于 2019-12-02 08:21:39
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 To summarize from the comments above, search(...) returns an array so you need to get a specific element, usually the first, before you can access

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

醉酒当歌 提交于 2019-12-02 03:22:54
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 { if Chef::Config[:solo] return (Array.new.push node) end search(:node, "recipes:my_server AND chef_environment:#{node.chef_environment} ") }.call.each do |server_node| node['postgresql']['pg_hba'] << { :comment => "# Enabling for #{server_node['ipaddress']}", :type => 'host', :db => 'all',

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

半腔热情 提交于 2019-12-01 17:37:26
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 service is installed and act based on that information? I'm running on Windows, if that's relevant. Take a