logo
down
shadow

How do I use a Chef Resource in a Library


How do I use a Chef Resource in a Library

By : user2954042
Date : November 21 2020, 07:31 AM
like below fixes the issue This looks like you should be creating a resource, either an LWRP or a normal Ruby class. In most cases the LWRP will be simpler and is probably what you want in this case.
cookbooks/mycook/resources/directory_structure.rb:
code :
default_action :create
attribute :domain, name_attribute: true
attribute :owner
attribute :group
action :create do
  directory "/var/www/#{@new_resource.domain}" do
    owner new_resource.owner
    group new_resource.group
  end
  directory "/var/www/#{@new_resource.domain}/production" do
    owner new_resource.owner
    group new_resource.group
  end

  directory "/var/www/#{@new_resource.domain}/staging" do
    owner new_resource.owner
    group new_resource.group
  end
end
mycook_directory_structure 'example.com' do
  owner 'me'
  group 'mygroup'
end


Share : facebook icon twitter icon
How can I use a Chef resource within a library module? (Or should I...)?

How can I use a Chef resource within a library module? (Or should I...)?


By : Lavy Hair
Date : March 29 2020, 07:55 AM
With these it helps Libraries are a way to abstract complex Ruby code away from a cookbook recipe.
To group resources (Chef DSL code) you should use either
code :
# cookbooks/common/definitions/common_stop_services.rb
define :common_stop_services, :services => [] do
  params[:services].each do |svc|
    service svc do
      action :stop
    end
  end
end
# my_cookbook/recipes/my_recipe.rb
common_stop_services "my_recipe_services" do
  services [ 'svc1', 'svc2' ]
end
Chef pass LWRP resource attribute to helper library

Chef pass LWRP resource attribute to helper library


By : Gwendal Le Gorju
Date : March 29 2020, 07:55 AM
Does that help I would put this method in resource itself as a private method. If you don't want to pass attributes inside that method, then it has to know private variables inside resource, so it has to be inside that resource.
Mocking library functions when unit testing chef custom resource

Mocking library functions when unit testing chef custom resource


By : Game App Studio
Date : March 29 2020, 07:55 AM
hope this fix your issue Managed to make this work by changing the mocking method... Those module functions are added into the action_class, and therefore at runtime they are methods on that specific instance of the resource's ActionClass. Not sure if my solution is right/ideal - but it does work:
code :
include CustomResource::Helpers

<snip>

it 'executes' do
  allow_any_instance_of(Chef::Resource::ActionClass).to receive(:my_helper?).and_return(true)
  expect_any_instance_of(Chef::Resource::ActionClass).to receive(:my_helper_method)
  expect { chef_run }.to_not raise_error
end
Which Chef resource can I execute multiple lines of BASH code using Chef's sensititve property?

Which Chef resource can I execute multiple lines of BASH code using Chef's sensititve property?


By : Karl Wessel Frogner
Date : March 29 2020, 07:55 AM
To fix this issue Answered in comments, true and false are lowercase in Ruby. Using True makes Ruby try to look for a const that doesn't exist.
Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume

Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume


By : user1991509
Date : March 29 2020, 07:55 AM
With these it helps I am trying to create a domain on a windows 2012 R2 server and it requires a reboot before the recipe can proceed: , The issue was resolved with the following logic:
code :
reboot "reboot server" do
  reason "init::chef - continue provisioning after reboot"
  action :nothing
  only_if {reboot_pending?}
end
Related Posts Related Posts :
  • macOS Mojave 'ruby/config.h' file not found
  • How to delete attr_accessor in ruby
  • How to reversibly escape a URL in Ruby so that it can be saved to the file system
  • Point belonging to which Polygon
  • How to implement custom mutating methods in Ruby?
  • Precedence operators in Ruby from Haskell?
  • How to install command line tools on OSX Mavericks
  • When making network requests, when should I use Threads vs Processes?
  • how to call method in one application from another application in ruby on rails
  • LoadError on line ["51"] when trying compass watch command
  • Why does `Dir[directory_path].empty?` return `false` all the time?
  • ruby conjunction and union operators
  • Ruby - watch for file with extension being updated
  • How do I have Ruby YAML dump a Hash subclass as a simple Hash?
  • How do I get ruby-prof to ignore Ruby core / standard library / gem methods?
  • How do I give my instance variable a getter?
  • syntax error, unexpected '=', expecting keyword_end
  • Symbol literal or a method
  • Singleton logger usage in ruby
  • Difficult code packaging design
  • Passing absent parameters
  • Is there a more efficient way of ensuring my database gets closed?
  • Take in escaped input in Ruby command line app
  • String with comma-separated values and newlines: split values and create arrays for each newline
  • Instance variables on Ruby main class
  • How do I cache user specific objects
  • How to specify the location of the chromedriver binary
  • How to setup "application/ld+json" schema.org meta data in rails 4 app
  • How to use String split[]
  • Capture Ruby Logger output for testing
  • Regex group match if present
  • Unusual use of module namespacing
  • Why doesn't this loop stop?
  • How do I run Rails/Rake from another directory?
  • Ruby Tempfile doesn't Create File on Disk
  • Consecutive letter frequency
  • Calling second-level function from the second level in Ruby
  • Ruby Method Name Interpolation
  • Weird behavior of #upcase! in Ruby
  • Ruby array access position in array
  • Ruby NameError: Undefined local variable
  • Using Nokogiri to validate XML: finding the line-nr of validation errors?
  • How to calling a function with arguments in one .rb script to another .rb script
  • Get and clear cookie using rest-client
  • invalid argument creating a ruby dev env with docker & fig
  • How can I better test equality for decorated objects?
  • Replace text in brackets gsub
  • Ruby's Array Combination Method
  • Don't have access to Heroku app
  • Take any hash keys and flatten into mixed array
  • Ruby On Rails Relationship Between Model, View, And Controller
  • Quitting method chain execution early
  • Data scrapping with Nokokiri and Pismo
  • Date format ends before converting entire input string
  • Rails 4: display values for lookups
  • Search for uppercased substring
  • Check params presence in Grape
  • How to create a method that checks if string1 can be rearranged to equal string2?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org