Class: Chef::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/rewind.rb

Instance Method Summary collapse

Instance Method Details

#rewind(resource_id, &block) ⇒ Object

rewinds an existing resource if it exists,

otherwise raises the Chef::Exceptions::ResourceNotFound exception
For example:
    #  recipe postgresql::server defines user "postgres"  and
    #  sets the home directory to /var/pgsql/9.2
    include_recipe "postgresql::user"

    rewind "user[postgres]" do
        home "/home/postgres"
    end

Parameters

resource<String>

String identifier for resource

block<Proc>

Block with attributes to rewind or create



21
22
23
24
25
26
27
28
29
30
# File 'lib/chef/rewind.rb', line 21

def rewind(resource_id,  &block)
  begin
    r = resources(resource_id)
    Chef::Log.info "Resource #{resource_id} found, now rewinding it"
    r.instance_exec(&block) if block
  rescue Chef::Exceptions::ResourceNotFound => e
    Chef::Log.info "Resource #{resource_id} not found, so rewind fails"
    raise e
  end
end

#unwind(resource_id) ⇒ Object

unwinds an existing resource if it exists,

otherwise raises the Chef::Exceptions::ResourceNotFound exception
For example:
    #  recipe postgresql::server defines user "postgres"  and
    #  sets the home directory to /var/pgsql/9.2
    include_recipe "postgresql::user"

    unwind "user[postgres]"

Parameters

resource<String>

String identifier for resource



42
43
44
# File 'lib/chef/rewind.rb', line 42

def unwind(resource_id)
  run_context.resource_collection.delete_resource resource_id
end