Class: Fhcap::Tasks::Chef::ChefTaskBase

Inherits:
TaskBase
  • Object
show all
Defined in:
lib/fhcap/tasks/chef/chef_task_base.rb

Instance Attribute Summary

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress

Methods included from KnifeHelper

#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #delete_chef_object, #knife_config, #knife_data_bag_delete, #knife_download, #knife_environment_delete, #knife_upload, #local_chef_server?, #with_chef_server, #with_local_chef_server

Methods included from ProvidersHelper

#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config

Methods included from ReposHelper

#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_dirty_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #git_diff, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir

Methods included from FhcapHelper

#cluster_template_names

Constructor Details

#initialize(options) ⇒ ChefTaskBase

Returns a new instance of ChefTaskBase.



8
9
10
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 8

def initialize(options)
  super
end

Instance Method Details

#knife_config_dirObject



12
13
14
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 12

def knife_config_dir
  config[:knife_dir] || File.join(config.default_dir, '.chef')
end

#knife_config_file_for(name) ⇒ Object



16
17
18
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 16

def knife_config_file_for(name)
  File.join(knife_config_dir, "knife-#{name}.rb")
end

#run_chef_client_cmd(cmd, server, capture = false) ⇒ Object



37
38
39
40
41
42
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 37

def run_chef_client_cmd(cmd, server, capture=false)
  cmd = "cd #{File.expand_path("..", knife_config_dir)} && chef-client -z #{cmd} -c #{knife_config_file_for(server)}"
  resp = thor.run(cmd, :capture => capture)
  thor.say resp if verbose && !capture
  resp
end

#run_knife_cmd(cmd, server, capture = true) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 29

def run_knife_cmd(cmd, server, capture=true)
  #ToDo [RHMAP-2898] Use knife object
  cmd = "cd #{File.expand_path("..", knife_config_dir)} && knife #{cmd} -c #{knife_config_file_for(server)}"
  resp = thor.run(cmd, :capture => capture)
  thor.say resp if verbose && !capture
  resp
end

#run_knife_ssh_cmd(query, cmd, server, options) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fhcap/tasks/chef/chef_task_base.rb', line 20

def run_knife_ssh_cmd(query, cmd, server, options)
  user = options[:knife_user] || 'hadmin'
  attr = options[:knife_attr] || 'cloud.public_ipv4'
  knife_options = options[:knife_options]
  ssh_cmd = ["ssh \"#{query}\" \"#{cmd}\" -x #{user} -a #{attr} #{knife_options}"]
  ssh_cmd << "--concurrency 1" if options[:series]
  run_knife_cmd(ssh_cmd.join(' '), server, false)
end