class Chef::Knife::ZeroConverge
Public Class Methods
new(argv = [])
click to toggle source
Calls superclass method
# File lib/chef/knife/zero_converge.rb, line 94 def initialize(argv = []) super self.configure_chef ## Command hook before_converge (Before launched Chef-Zero) if Chef::Config[:knife][:before_converge] ::Knife::Zero::Helper.hook_shell_out!('before_converge', ui, Chef::Config[:knife][:before_converge]) end if @config[:json_attribs] @config[:chef_client_json] = fetch_json_from_url end validate_options! @name_args = [@name_args[0], start_chef_client] end
Public Instance Methods
fetch_json_from_url()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 175 def fetch_json_from_url config_fetcher = Chef::ConfigFetcher.new(@config[:json_attribs]) config_fetcher.fetch_json end
json_attribs_given?()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 171 def json_attribs_given? !config[:json_attribs].nil? && !config[:json_attribs].empty? end
json_attribs_without_override_given?()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 162 def json_attribs_without_override_given? if json_attribs_given? return true unless override_runlist_given? else false end false end
named_run_list_given?()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 158 def named_run_list_given? !config[:named_run_list].nil? && !config[:named_run_list].empty? end
override_and_named_given?()
click to toggle source
True if policy_name and run_list are both given
# File lib/chef/knife/zero_converge.rb, line 150 def override_and_named_given? override_runlist_given? && named_run_list_given? end
override_runlist_given?()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 154 def override_runlist_given? !config[:override_runlist].nil? && !config[:override_runlist].empty? || @config[:chef_client_json]&.key?('run_list') end
start_chef_client()
click to toggle source
# File lib/chef/knife/zero_converge.rb, line 112 def start_chef_client # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/CyclomaticComplexity client_path = @config[:use_sudo] || Chef::Config[:knife][:use_sudo] ? 'sudo ' : '' client_path = @config[:chef_client_path] ? "#{client_path}#{@config[:chef_client_path]}" : "#{client_path}chef-client" s = String.new(client_path) s << ' -l debug' if @config[:verbosity] && @config[:verbosity] >= 2 s << " -S http://127.0.0.1:#{::Knife::Zero::Helper.zero_remote_port}" s << " -o #{@config[:override_runlist]}" if @config[:override_runlist] s << ' -j /etc/chef/chef_client_json.json' if @config[:json_attribs] s << " --splay #{@config[:splay]}" if @config[:splay] s << " -n #{@config[:named_run_list]}" if @config[:named_run_list] s << " --config #{@config[:node_config_file]}" s << ' --skip-cookbook-sync' if @config[:skip_cookbook_sync] s << ' --no-color' unless @config[:color] s << " -E #{@config[:environment]}" if @config[:environment] s << " --chef-license #{@config[:chef_license]}" if @config[:chef_license] s << ' -W' if @config[:why_run] Chef::Log.info 'Remote command: ' + s s end
validate_options!()
click to toggle source
For support policy_document_databag(old style)
# File lib/chef/knife/zero_converge.rb, line 133 def validate_options! if override_and_named_given? ui.error('--override_runlist and --named_run_list are exclusive') exit 1 end if json_attribs_without_override_given? ui.error( '--json-attributes must be used with --override-runlist ' \ 'or passed json should includes key `run-list` ' \ 'to avoid unexpected updating local node object.' ) exit 1 end true end