Giter VIP home page Giter VIP logo

poise-ruby's Introduction

Poise

Build Status Gem Version Cookbook Version Coverage Gemnasium License

What is Poise?

The poise cookbook is a set of libraries for writing reusable cookbooks. It provides helpers for common patterns and a standard structure to make it easier to create flexible cookbooks.

Writing your first resource

Rather than LWRPs, Poise promotes the idea of using normal, or "heavy weight" resources, while including helpers to reduce much of boilerplate needed for this. Each resource goes in its own file under libraries/ named to match the resource, which is in turn based on the class name. This means that the file libraries/my_app.rb would contain Chef::Resource::MyApp which maps to the resource my_app.

An example of a simple shell to start from:

require 'poise'
require 'chef/resource'
require 'chef/provider'

module MyApp
  class Resource < Chef::Resource
    include Poise
    provides(:my_app)
    actions(:enable)

    attribute(:path, kind_of: String)
    # Other attribute definitions.
  end

  class Provider < Chef::Provider
    include Poise
    provides(:my_app)

    def action_enable
      notifying_block do
        ... # Normal Chef recipe code goes here
      end
    end
  end
end

Starting from the top, first we require the libraries we will be using. Then we create a module to hold our resource and provider. If your cookbook declares multiple resources and/or providers, you might want additional nesting here. Then we declare the resource class, which inherits from Chef::Resource. This is similar to the resources/ file in an LWRP, and a similar DSL can be used. We then include the Poise mixin to load our helpers, and then call provides(:my_app) to tell Chef this class will implement the my_app resource. Then we use the familiar DSL, though with a few additions we'll cover later.

Then we declare the provider class, again similar to the providers/ file in an LWRP. We include the Poise mixin again to get access to all the helpers and call provides() to tell Chef what provider this is. Rather than use the action :enable do ... end DSL from LWRPs, we just define the action method directly. The implementation of action comes from a block of recipe code wrapped with notifying_block to capture changes in much the same way as use_inline_resources, see below for more information about all the features of notifying_block.

We can then use this resource like any other Chef resource:

my_app 'one' do
  path '/tmp'
end

Helpers

While not exposed as a specific method, Poise will automatically set the resource_name based on the class name.

Notifying Block

As mentioned above, notifying_block is similar to use_inline_resources in LWRPs. Any Chef resource created inside the block will be converged in a sub-context and if any have updated it will trigger notifications on the current resource. Unlike use_inline_resources, resources inside the sub-context can still see resources outside of it, with lookups propagating up sub-contexts until a match is found. Also any delayed notifications are scheduled to run at the end of the main converge cycle, instead of the end of this inner converge.

This can be used to write action methods using the normal Chef recipe DSL, while still offering more flexibility through subclassing and other forms of code reuse.

Include Recipe

In keeping with notifying_block to implement action methods using the Chef DSL, Poise adds an include_recipe helper to match the method of the same name in recipes. This will load and converge the requested recipe.

Resource DSL

To make writing resource classes easier, Poise exposes a DSL similar to LWRPs for defining actions and attributes. Both actions and default_action are just like in LWRPs, though default_action is rarely needed as the first action becomes the default. attribute is also available just like in LWRPs, but with some enhancements noted below.

One notable difference over the standard DSL method is that Poise attributes can take a block argument.

Template Content

A common pattern with resources is to allow passing either a template filename or raw file content to be used in a configuration file. Poise exposes a new attribute flag to help with this behavior:

attribute(:name, template: true)

This creates four methods on the class, name_source, name_cookbook, name_content, and name_options. If the name is set to '', no prefix is applied to the function names. The content method can be set directly, but if not set and source is set, then it will render the template and return it as a string. Default values can also be set for any of these:

attribute(:name, template: true, default_source: 'app.cfg.erb',
          default_options: {host: 'localhost'})

As an example, you can replace this:

if new_resource.source
  template new_resource.path do
    source new_resource.source
    owner 'app'
    group 'app'
    variables new_resource.options
  end
else
  file new_resource.path do
    content new_resource.content
    owner 'app'
    group 'app'
  end
end

with simply:

file new_resource.path do
  content new_resource.content
  owner 'app'
  group 'app'
end

As the content method returns the rendered template as a string, this can also be useful within other templates to build from partials.

Lazy Initializers

One issue with Poise-style resources is that when the class definition is executed, Chef hasn't loaded very far so things like the node object are not yet available. This means setting defaults based on node attributes does not work directly:

attribute(:path, default: node['myapp']['path'])
...
NameError: undefined local variable or method 'node'

To work around this, Poise extends the idea of lazy initializers from Chef recipes to work with resource definitions as well:

attribute(:path, default: lazy { node['myapp']['path'] })

These initializers are run in the context of the resource object, allowing complex default logic to be moved to a method if desired:

attribute(:path, default: lazy { my_default_path })

def my_default_path
  ...
end

Option Collector

Another common pattern with resources is to need a set of key/value pairs for configuration data or options. This can done with a simple Hash, but an option collector attribute can offer a nicer syntax:

attribute(:mydata, option_collector: true)
...

my_app 'name' do
  mydata do
    key1 'value1'
    key2 'value2'
  end
end

This will be converted to {key1: 'value1', key2: 'value2'}. You can also pass a Hash to an option collector attribute just as you would with a normal attribute.

Debugging Poise

Poise has its own extra-verbose level of debug logging that can be enabled in three different ways. You can either set the environment variable $POISE_DEBUG, set a node attribute node['POISE_DEBUG'], or touch the file /POISE_DEBUG. You will see a log message Extra verbose logging enabled at the start of the run to confirm Poise debugging has been enabled. Make sure you also set Chef's log level to debug, usually via -l debug on the command line.

Upgrading from Poise 1.x

The biggest change when upgrading from Poise 1.0 is that the mixin is no longer loaded automatically. You must add require 'poise' to your code is you want to load it, as you would with normal Ruby code outside of Chef. It is also highly recommended to add provides(:name) calls to your resources and providers, this will be required in Chef 13 and will display a deprecation warning if you do not. This also means you can move your code out of the Chef module namespace and instead declare it in your own namespace. An example of this is shown above.

Sponsors

The Poise test server infrastructure is generously sponsored by Rackspace. Thanks Rackspace!

License

Copyright 2013-2016, Noah Kantrowitz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

poise-ruby's People

Contributors

coderanger avatar petracvv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

poise-ruby's Issues

Running the Bundle Install Resource with a Cron Task

Hello,

I'm trying to use the bundle_install resource inside a cron job that calls chef-client for updating my application server. The only problem is that when I get to this point I receive the following error:

#<TypeError: application_bundle_install[/home/deploy/projects/app/] (app_deploy::default line 30) had an error: TypeError: no implicit conversion of false into String> had an error:
application_bundle_install[/home/deploy/projects/app/] (app_deploy::default line 30) had an error: TypeError: no implicit conversion of false into String
Description: Error executing action `install` on resource 'application_bundle_install[/home/deploy/projects/app/]'

Here is the cookbook stacktrace:

/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:46:in `split'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:46:in `default_gem_binary'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:34:in `block in <module:Resource>'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/lazy_default.rb:57:in `set_or_return'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/win32_user.rb:60:in `set_or_return'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/lwrp_polyfill.rb:114:in `block in attribute'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:177:in `poise_gem_bindir'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:131:in `bundler_binary'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:219:in `bundler_command'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:160:in `run_bundler'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:119:in `action_install'

Here's my resource declaration:

# In /var/chef/cache/cookbooks/app_deploy/recipes/default.rb

 30:   bundle_install do
 31:     path "#{app_path}/"
 32:     user 'deploy'
 33:   end
 34: end

Here's my compiled resource:

# Declared in /var/chef/cache/cookbooks/app_deploy/recipes/default.rb:30:in `block in from_file'

application_bundle_install("/home/deploy/projects/app/") do
  action [:install]
  default_guard_interpreter :default
  declared_type :application_bundle_install
  cookbook_name "app_deploy"
  recipe_name "default"
  parent application[/home/deploy/projects/app/]
  path "/home/deploy/projects/app/"
  user "deploy"
  parent_ruby nil
end

And finally my full stacktrace is:

/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:46:in `split'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:46:in `default_gem_binary'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_command_mixin.rb:34:in `block in <module:Resource>'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/property.rb:648:in `instance_exec'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/property.rb:648:in `exec_in_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/property.rb:666:in `stored_value_to_output'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/property.rb:352:in `get'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/mixin/params_validate.rb:471:in `get'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/mixin/params_validate.rb:482:in `call'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/mixin/params_validate.rb:123:in `set_or_return'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/lazy_default.rb:57:in `set_or_return'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/win32_user.rb:60:in `set_or_return'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/lwrp_polyfill.rb:114:in `block in attribute'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:177:in `poise_gem_bindir'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:131:in `bundler_binary'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:219:in `bundler_command'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:160:in `run_bundler'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:119:in `action_install'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/provider.rb:171:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource.rb:591:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/runner.rb:70:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/runner.rb:98:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/runner.rb:98:in `each'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/runner.rb:98:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/runner.rb:97:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:715:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:710:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:710:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:749:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:286:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:291:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:244:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:232:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:441:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:59:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:58:in `load'
/usr/bin/chef-client:58:in `<main>'

Any help with this issue is greatly appreciated, I look forward to your response!

No SCL repository package for redhat 7.4 when trying to install Ruby 2.4

Attempting to setup 2.4 runtime, produces the following error:

Generated at 2018-02-27 20:49:32 +0000
PoiseLanguages::Error: No SCL repoistory package for redhat 7.4
/var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/scl/mixin.rb:43:in `block in scl_package'
/var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/scl/mixin.rb:42:in `tap'
/var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/scl/mixin.rb:42:in `scl_package'
/var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/scl/mixin.rb:26:in `install_scl_package'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_providers/scl.rb:45:in `install_ruby'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_providers/base.rb:44:in `block in action_install'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subcontext_block.rb:54:in `instance_eval'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subcontext_block.rb:54:in `subcontext_block'
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/notifying_block.rb:67:in `notifying_block'
/var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_providers/base.rb:43:in `action_install'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider.rb:171:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource.rb:591:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/runner.rb:70:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/runner.rb:98:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/runner.rb:98:in `each'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/runner.rb:98:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/runner.rb:97:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/client.rb:718:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/client.rb:713:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/client.rb:713:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/client.rb:752:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/client.rb:286:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:291:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:279:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:279:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:244:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:232:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application/client.rb:457:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application/client.rb:441:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/application.rb:59:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/bin/chef-client:26:in `<top (required)>'
/bin/chef-client:58:in `load'
/bin/chef-client:58:in `<main>'

rh-ruby24 is available in the SCL repository provided by Red Hat.

CentOs support

This is just to add an issue so that people can subscribe and be notified when CentOS support is implemented.

The README says (from Jan 2, 2014):

CentOS 5 and 6 support is coming soon, and possibly Fedora 19.

poise-ruby fails during compile

[root@ip-10-10-0-79 instance]# chef-client -r XXXXXX::appserver_role -E develop
Starting Chef Client, version 12.4.0
resolving cookbooks for run list: ["XXXXXX::appserver_role"]
Synchronizing Cookbooks:

  • XXXXXX
  • poise-ruby
  • poise
  • yum
  • sudo
  • ssh-keys
  • users
  • chef-client
  • apt
  • chef_handler
  • windows
  • logrotate
  • application_ruby
  • application
  • unicorn
  • cron
  • gluster
  • apache2
  • freebsd
  • passenger_apache2
  • pacman
  • iptables
  • runit
  • build-essential
  • packagecloud
    Compiling Cookbooks...

Recipe Compile Error in /var/chef/cache/cookbooks/poise-ruby/libraries/poise_ruby.rb

NameError

uninitialized constant Chef::Resource::PoiseRuby::Poise

Cookbook Trace:

/var/chef/cache/cookbooks/poise-ruby/libraries/poise_ruby.rb:21:in <class:PoiseRuby>' /var/chef/cache/cookbooks/poise-ruby/libraries/poise_ruby.rb:20:inclass:Chef'
/var/chef/cache/cookbooks/poise-ruby/libraries/poise_ruby.rb:19:in `<top (required)>'

Relevant File Content:

/var/chef/cache/cookbooks/poise-ruby/libraries/poise_ruby.rb:

14: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: # See the License for the specific language governing permissions and
16: # limitations under the License.
17: #
18:
19: class Chef
20: class Resource::PoiseRuby < Resource
21>> include Poise
22: actions(:upgrade, :install, :remove)
23:
24: attribute(:flavor, name_attribute: true)
25: attribute(:version, kind_of: String)
26:
27: def package_name
28: "poise-#{flavor}"
29: end
30: end

Running handlers:
Running handlers complete
Chef Client failed. 0 resources updated in 2.740744467 seconds


The recipe itself looks like this:

==================== XXXXXX::appserver_role
include_recipe "XXXXXX::base_role"
ruby_runtime '1.8.7'

%w[mysql-devel GeoIP GeoIP-devel zlib-devel].each do |p|
package p
end

user 'XXXXXX''
include_recipe "XXXXXX::deploy_app"

Metadata.rb file are missing from source control

Can the metadata.rb file can be added to this cookbook? I have a script that mirrored this repo internally but berks complains when trying to use mirrored git location as cookbook rule in top-level cookbook Berksfile.

It works when you get it from supermarket because for some reason the metadata.rb and metadata.json files are getting added before you push cookbook there.

The same issue affects poise and poise-service cookbooks.

Related
poise/poise#22
poise/poise-service#6

reload ruby ohai plugin when run as recipe

People using poise-ruby as a recipe probably want the ruby to be run as their main ruby. So it would be useful to rerun ohai's ruby plugin, presumably after adding setting $PATH. e.g.

include_recipe 'poise-ruby'

poise_ruby_path = "/opt/#{node['poise-ruby']['ruby']}/bin"
ENV['PATH'] = "#{poise_ruby_path}:#{ENV['PATH']}"

execute 'add poise-ruby to /etc/environment' do
  command <<-EOS
    TEMP=`mktemp -t environment.XXXXXXXXXX` || exit 1
    cat /etc/environment |
    sed 's/PATH=.*$/PATH="#{ENV['PATH'].gsub('/','\/')}"/' > $TEMP &&
    cat $TEMP > /etc/environment
    rm $TEMP
  EOS

  not_if "grep 'PATH=.*#{poise_ruby_path}'  /etc/environment"
end

ohai 'ruby' do
  plugin 'ruby'
  action :reload
end

I've had to use this terrible hack to allow the passenger_apache2 cookbook to auto discover the right ruby.

Compile error with Chef 14.3

Getting a compile error on Chef 14.3.37. This worked on 14.2.0.

Compiling Cookbooks...

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/poise-ruby/libraries/default.rb
================================================================================

FrozenError
-----------
can't modify frozen Array

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:220:in `included'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `include'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `poise_subresource_container'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise.rb:93:in `block in Poise'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:34:in `include'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:34:in `<class:Resource>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:33:in `<module:RubyRuntime>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:25:in `<module:Resources>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:22:in `<module:PoiseRuby>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/ruby_runtime.rb:21:in `<top (required)>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources.rb:20:in `<top (required)>'
  /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/cheftie.rb:17:in `<top (required)>'
  /var/chef/cache/cookbooks/poise-ruby/libraries/default.rb:19:in `<top (required)>'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:

213:                @container_default
214:              end
215:            end
216:
217:            def included(klass)
218:              super
219:              klass.extend(ClassMethods)
220>>             klass.const_get(:HIDDEN_IVARS) << :@subcontexts
221:              klass.const_get(:FORBIDDEN_IVARS) << :@subcontexts
222:            end
223:          end
224:
225:          extend ClassMethods
226:        end
227:      end
228:    end
229:  end

Additional information:
-----------------------
      Ruby objects are often frozen to prevent further modifications
      when they would negatively impact the process (e.g. values inside
      Ruby's ENV class) or to prevent polluting other objects when default
      values are passed by reference to many instances of an object (e.g.
      the empty Array as a Chef resource default, passed by reference
      to every instance of the resource).

      Chef uses Object#freeze to ensure the default values of properties
      inside Chef resources are not modified, so that when a new instance
      of a Chef resource is created, and Object#dup copies values by
      reference, the new resource is not receiving a default value that
      has been by a previous instance of that resource.

      Instead of modifying an object that contains a default value for all
      instances of a Chef resource, create a new object and assign it to
      the resource's parameter, e.g.:

      fruit_basket = resource(:fruit_basket, 'default')

      # BAD: modifies 'contents' object for all new fruit_basket instances
      fruit_basket.contents << 'apple'

      # GOOD: allocates new array only owned by this fruit_basket instance
      fruit_basket.contents %w(apple)


System Info:
------------
chef_version=14.3.37
platform=ubuntu
platform_version=18.04
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
program_name=chef-client worker: ppid=13328;start=16:47:30;
executable=/opt/chef/bin/chef-client

ruby_build provider not implemented as README implies

The README implies that the :ruby_build provider is implemented, but it doesn't appear to be. The following recipe results in an error.

ruby_runtime 'myapp' do
  provider :ruby_build
  version '2.3.0'
end
ERROR: No provider found to match 'ruby_build'

As expected, looking through the src for both master and the 2.1.1 tag, there doesn't appear to actually be any ruby_build provider, countering what's in the README.

Is the README just incorrect? Or are you in the process of beginning to use poise/poise-ruby-build?

Adjust documentation

For the bundle_install resource you still state that it has a bundler_version method although it appears you removed it a couple of months ago.

Specify source for ruby_runtime

I am attempting to install ruby version 2.3 on Red Hat using SLC. Here is my code for calling the resource:

ruby_runtime 'hal' do
  provider :scl
  version '2.3'
end

When running this resource, I get the following error:

================================================================================
           Error executing action `install` on resource 'ruby_runtime[hal]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           ruby_gem[bundler] (/tmp/kitchen/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/ruby_providers/base.rb line 109) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2
'
           ---- Begin output of /opt/rh/rh-ruby23/root/usr/bin/gem install "bundler" -q --no-rdoc --no-ri  ----
           STDOUT:
           STDERR: ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
              Unable to download data from https://rubygems.org/ - timed out (https://api.rubygems.org/specs.4.8.gz)
           ---- End output of /opt/rh/rh-ruby23/root/usr/bin/gem install "bundler" -q --no-rdoc --no-ri  ----
           Ran /opt/rh/rh-ruby23/root/usr/bin/gem install "bundler" -q --no-rdoc --no-ri  returned 2

This is most likely due to the fact that our systems can not go out externally to fetch gems. We have an internal gems server that we leverage, but I am not sure if there is a way to specify a gems source with this resource.

PGP Server Connection Timing Out

The command:

apt-key adv --keyserver hkp://pgp.mit.edu --recv 594F6D7656399B5C

has the following erorr:

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.6APAK3EKgr --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://pgp.mit.edu --recv 594F6D7656399B5C
gpg: requesting key 56399B5C from hkp server pgp.mit.edu
?: pgp.mit.edu: Connection timed out
gpgkeys: HTTP fetch error 7: couldn't connect: Connection timed out
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0

which is being called from https://github.com/poise/poise-ruby/blob/master/libraries/poise_ruby.rb#L89

rubygems 2.2.2

Hi there,

Any plans on releasing newer ruby&rubygems for ruby.poise.io? I'm currently stuck with trying to upgrade poise/berkshelf-api cookbook to use the latest berkshelf-api because rubygems 2.2.0 are buggy and go into indefinite loop on gem install.

Would you recommend waiting for newer packages, switching to another cookbook or patching poise/berkshelf-api to use another cookbook to build ruby?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.