Skip to content

dergachev/chef_extend_lwrp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 git@github.com: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

About

Chef cookbook demonstrating how to extend an LWRP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages