Class: Qurd::Action::Chef

Inherits:
Qurd::Action show all
Defined in:
lib/qurd/action/chef.rb

Overview

Clean up chef client and node data

Examples:

Chef configuration

chef_configuration: "/etc/chef/some_knife_config.rb"

Instance Attribute Summary

Attributes inherited from Qurd::Action

#context, #message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Qurd::Action

#aws_credentials, #initialize, #inspect, #launch, #region, #run_after

Methods included from Mixins::Configuration

#qurd_config, #qurd_configuration, #qurd_logger, #qurd_logger!

Methods included from Mixins::AwsClients

#aws_client, #aws_retryable

Constructor Details

This class inherits a constructor from Qurd::Action

Class Method Details

.configure(_action) ⇒ Object

Add a setter and getter for Message chef_node chef_client and configure Chef using Configuration chef_configuration or the default /etc/chef/knife.rb. If Configuration log_file is defined, Chef will log to it.

Parameters:

  • _action (String)

    the name of the action being configured



17
18
19
20
21
22
23
# File 'lib/qurd/action/chef.rb', line 17

def self.configure(_action)
  return if @configure_done
  configure_chef
  Qurd::Message.add_accessor(:chef_node)
  Qurd::Message.add_accessor(:chef_client)
  @configure_done = true
end

.configure_chefObject

Parse Chef’s configuration file, as defined in qurd.yml, set Chef’s log_level, and Chef’s log_location



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/qurd/action/chef.rb', line 27

def self.configure_chef
  config = File.expand_path(qurd_configuration.chef_configuration ||
                            '/etc/chef/knife.rb')
  qurd_logger.debug("Configuring Chef for using #{config}")
  ::Chef::Config.from_file(config)
  ::Chef::Config[:log_level] = qurd_configuration.log_level
  if qurd_configuration.log_file_io
    qurd_logger.debug('Setting chef log file to ' \
                      "'#{qurd_configuration.log_file_io.path}'")
    ::Chef::Config[:log_location] = qurd_configuration.log_file_io
  end
end

Instance Method Details

#run_beforeObject

Find the node, using the instance_id of the message



41
42
43
44
# File 'lib/qurd/action/chef.rb', line 41

def run_before
  find_chef_node
  find_chef_client
end

#terminateObject

Delete the node, if the message did not fail other processing steps and dry_run is not true

See Also:

  • Qurd::Action::Chef.{{#Qurd{#Qurd::Message}


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qurd/action/chef.rb', line 49

def terminate
  if message.failed?
    qurd_logger.warn('Not deleting, message failed to process')
  elsif qurd_configuration.dry_run
    check_dry_run
  else
    qurd_logger.debug('Deleting')
    message.chef_node.destroy unless message.chef_node.nil?
    message.chef_client.destroy unless message.chef_client.nil?
  end
end

#testObject

Respond to test actions



62
63
64
# File 'lib/qurd/action/chef.rb', line 62

def test
  qurd_logger.info('Test')
end