module ChefRunDeck::Chef
> This is the Chef
module. It interacts with the Chef
server¶ ↑
Public Instance Methods
admin_api_client()
click to toggle source
# File lib/chef-rundeck/chef.rb, line 33 def admin_api_client # => Configure an Administrative Chef API Client ChefAPI.endpoint = Config.chef_api_endpoint ChefAPI.client = Config.chef_api_admin ChefAPI.key = Config.chef_api_admin_key end
api_client()
click to toggle source
delete(node)
click to toggle source
> Delete a Node Object¶ ↑
# File lib/chef-rundeck/chef.rb, line 66 def delete(node) # => Make sure the Node Exists return 'Node not found on Chef Server' unless Node.exists?(node) # => Initialize the Admin API Client Settings admin_api_client # => Delete the Client & Node Object Client.delete(node) Node.delete(node) 'Client/Node Deleted from Chef Server' end
get_node(node, casecomp = false)
click to toggle source
list()
click to toggle source
reset!()
click to toggle source
# File lib/chef-rundeck/chef.rb, line 40 def reset! # => Reset the Chef API Configuration ChefAPI.reset! # => Clear Transient Configuration Config.clear(:rundeck) end
run_list(node)
click to toggle source
search(pattern = '*:*')
click to toggle source
# File lib/chef-rundeck/chef.rb, line 165 def search(pattern = '*:*') # rubocop: disable AbcSize # => Initialize the Configuration transient_settings # => Pull in the Pattern pattern = Config.rundeck[:pattern] # => Execute the Chef Search result = PartialSearch.query(:node, search_filter, pattern, start: 0) # => Custom-Tailor the Resulting Objects result.rows.collect do |node| { nodename: node['name'], hostname: build_hostname(node), osArch: node['kernel_machine'], osFamily: node['platform'], osName: node['platform'], osVersion: node['platform_version'], description: node['name'], roles: node['roles'].sort.join(','), recipes: node['recipes'].sort.join(','), tags: [node['roles'], node['chef_environment'], node['tags']].flatten.sort.join(','), environment: node['chef_environment'], editUrl: ::File.join(Config.chef_api_endpoint, 'nodes', node['name']), username: remote_username(node) }.merge(custom_attributes(node)).reject { |_k, v| v.nil? || String(v).empty? } end end
Private Instance Methods
build_hostname(node)
click to toggle source
custom_attributes(node)
click to toggle source
default_search_filter()
click to toggle source
> Base Search Filter Definition¶ ↑
# File lib/chef-rundeck/chef.rb, line 110 def default_search_filter { name: ['name'], kernel_machine: ['kernel', 'machine'], kernel_os: ['kernel', 'os'], fqdn: ['fqdn'], run_list: ['run_list'], roles: ['roles'], recipes: ['recipes'], chef_environment: ['chef_environment'], platform: ['platform'], platform_version: ['platform_version'], tags: ['tags'], hostname: ['hostname'], rd_hostname: ['rd_hostname'], rd_ssh_port: ['rd_ssh_port'], rd_winrm_port: ['rd_winrm_port'], rd_username: ['rd_username'] } end
project()
click to toggle source
> Try to Parse Project-Specific Settings¶ ↑
# File lib/chef-rundeck/chef.rb, line 86 def project projectname = Config.query_params['project'] return {} unless projectname settings = Util.parse_json_config(Config.projects_file, false) return {} unless settings && settings[projectname] settings[projectname] end
remote_hostname(node)
click to toggle source
remote_port(node)
click to toggle source
> Determine the Remote Port¶ ↑
# File lib/chef-rundeck/chef.rb, line 213 def remote_port(node) # => WinRM if Windows if node['platform'] == 'windows' [ node['rd_winrm_port'], Config.query_params['winrm_port'], project['winrm_port'] ].find { |winrm_port| winrm_port } else # => SSH for Everything Else [ node['rd_ssh_port'], Config.query_params['ssh_port'], project['ssh_port'] ].find { |ssh_port| ssh_port } end end
remote_username(node)
click to toggle source
search_filter()
click to toggle source
search_filter_additions()
click to toggle source
> Parse Additional Filter Elements¶ ↑
> Default Elements can be removed by passing them in here as null or empty¶ ↑
# File lib/chef-rundeck/chef.rb, line 136 def search_filter_additions attribs = {} Array(Config.rundeck[:extras]).each do |attrib| attribs[attrib.to_sym] = [attrib] end # => Return the Custom Filter Additions Hash attribs end
transient_settings()
click to toggle source
> Construct Query-Specific Configuration
¶ ↑
# File lib/chef-rundeck/chef.rb, line 97 def transient_settings # => Build the Configuration cfg = {} cfg[:pattern] = Config.query_params['pattern'] || project['pattern'] || '*:*' cfg[:extras] = Util.serialize_csv(Config.query_params['extras']) || project['extras'] # => Make the Settings Available via the Config Object Config.add(rundeck: cfg) end