Created
August 6, 2011 18:47
-
-
Save anonymous/1129625 to your computer and use it in GitHub Desktop.
add :reconfig action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chef/mixin/command' | |
# Modify constructor of the Package resource to allow the action :reconfig | |
module AddReconfigAction | |
def self.included( klass ) | |
klass.class_eval do | |
alias_method :init_pre, :initialize | |
def initialize( *args ) | |
init_pre( *args ) | |
@allowed_actions.push( :reconfig ) | |
end | |
end | |
end | |
end | |
class Chef | |
class Resource | |
class Package < Chef::Resource | |
include AddReconfigAction | |
end | |
end | |
end | |
# add generic :reconfig action skeleton to generic package provider | |
class Chef | |
class Provider | |
class Package < Chef::Provider | |
def action_reconfig | |
if @current_resource.version == nil then | |
Chef::Log.debug("#{@new_resource} is NOT installed - nothing to do") | |
return | |
end | |
preseed_package( @new_resource.package_name, @current_resource.version ) if @new_resource.response_file | |
status = reconfig_package( @new_resource.package_name ) | |
@new_resource.updated_by_last_action(true) if status | |
Chef::Log.info( "#{@new_resource} reconfigured" ) | |
end | |
def reconfig_package( name ) | |
raise( Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reconfig" ) | |
end | |
end | |
end | |
end | |
# implement new :reconfig action for the apt provider | |
class Chef | |
class Provider | |
class Package | |
class Apt < Chef::Provider::Package | |
def reconfig_package( name ) | |
Chef::Log.info("#{@new_resource} running dpkg-reconfigure #{name}") | |
run_command_with_systems_locale( | |
:command => "dpkg-reconfigure #{name}", | |
:environment => { | |
"DEBIAN_FRONTEND" => "noninteractive" | |
} | |
) | |
end | |
def get_preseed_file(name, version) | |
resource = preseed_resource(name, version) | |
resource.run_action('create') | |
Chef::Log.debug("#{@new_resource} fetched preseed file to #{resource.path}") | |
resource.path | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment