Skip to content

Latest commit

 

History

History
100 lines (73 loc) · 3.98 KB

README.md

File metadata and controls

100 lines (73 loc) · 3.98 KB

extend_lwrp

Description

Example cookbook showing how to use Ruby mixins to extend an LWRP provider from a recipe

Installation

Clone this repository into your CHEF-REPO/cookbooks/extend_lwrp:

  # Be sure to name the cookbook "extend_lwrp", not "chef_extend_lwrp"
  git clone [email protected]:dergachev/chef_extend_lwrp.git extend_lwrp 

Usage

This cookbook defines a resource greeting, which outputs a log message with a greeting. Include recipe[extend_lwrp::base] to see the base greeting LWRP in action. Include recipe[extend_lwrp::overriden] to see the overriden greeting lwrp in action. Look at the all the code to learn about how this was achieved.

Trying it out with vagrant/shef

Start shef in the vagrant vm:

  vagrat ssh
  cd /tmp/vagrant-chef-1 #or whatever the right path is
  sudo shef -s -c ./solo.rb -j ./dna.json # solo modo, with default vagrant chef-solo config

Run the following in shef on vagrant:

  # first confirm that the default greeting behavior
  chef >          recipe                                   #enter recipe mode
  chef:recipe >   extend_lwrp_greeting("Base Bob") # loads greeting resource with default action 
  chef:recipe >   run_chef    # executes loaded resources; see that default greeting is printed

  # now confirm that overriding works
  chef:recipe >   class Chef::Provider::ExtendLwrpGreeting ; def greeting_format(name); return "Bonjour, " + name ; end ; end
  chef:recipe >   run_chef    # executes loaded resources; see that the overriden greeting is printed

Resources

LWRP

The essentials:

Other background:

  # the following is how to do static execution of resources
  chef > recipe
  chef:recipe >   p = package "netcat" do ; action :nothing ; end
  chef:recipe >   p.run_action :install

Discussions about LWRP subclassing:

Shef

NB: If you edit a recipe and add "breakpoint 'Name'", and shef will break to it. However I never figured out how that's useful, since shef seems to only break outside resource definitions

Ruby mixins

Motivation

This cookbook was written in the course of figuring out how to extend fnichol/chef-homesick to make it compatible with SSH agent forwarding.
See https://github.com/dergachev/chef_homesick_agent