Class: Chef::Knife::ZeroBootstrap

Inherits:
Bootstrap show all
Includes:
ZeroBase
Defined in:
lib/chef/knife/zero_bootstrap.rb

Instance Method Summary collapse

Methods included from ZeroBase

included

Instance Method Details

#build_knifezero_attributes_for_nodeObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/chef/knife/zero_bootstrap.rb', line 103

def build_knifezero_attributes_for_node
  ## Return to Pending.
  # ssh_url = String.new("ssh://")
  # ssh_url << config[:ssh_user] || Chef::Config[:knife][:ssh_user]
  # ssh_url << "@"
  # ssh_url << server_name
  # ssh_url << ":"
  # port =  config[:ssh_port] || Chef::Config[:knife][:ssh_port] || 22
  # ssh_url << port.to_s
  attr = Mash.new
  attr[:knife_zero] = {
    host: server_name
    # ssh_url: ssh_url
  }
  attr
end

#resolve_node_nameObject



120
121
122
123
124
# File 'lib/chef/knife/zero_bootstrap.rb', line 120

def resolve_node_name
  return @config[:chef_node_name] if @config[:chef_node_name]

  @cli_arguments.first.split('@').last
end

#runObject

rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/CyclomaticComplexity



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/chef/knife/zero_bootstrap.rb', line 47

def run # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/CyclomaticComplexity
  ## Command hook before_bootstrap (After launched Chef-Zero)
  if Chef::Config[:knife][:before_bootstrap]
    ::Knife::Zero::Helper.hook_shell_out!(
      'before_bootstrap',
      ui,
      Chef::Config[:knife][:before_bootstrap]
    )
  end

  case @config[:alter_project]
  when 'cinc'
    @config[:bootstrap_url] = 'https://omnitruck.cinc.sh/install.sh'
  end

  if @config[:bootstrap_converge]
    unless @config[:overwrite_node_object]
      q = Chef::Search::Query.new
      node_name = resolve_node_name
      result = q.search(:node, "name:#{node_name} OR knife_zero_host:#{node_name}")
      if result.last.positive?
        ui.warn(%{Node "#{node_name}" already exist. [Found #{result.last} Node(s) in local search.] (You can skip asking with --overwrite option.)})
        if result.last == 1
          ui.confirm(%{Overwrite it }, true, false)
        else
          ui.confirm(%{Overwrite one of them }, true, false)
        end
      end
    end
  end

  if @config[:first_boot_attributes_from_file]
    @config[:first_boot_attributes_from_file] = @config[:first_boot_attributes_from_file].merge(build_knifezero_attributes_for_node)
  else
    @config[:first_boot_attributes] = if @config[:first_boot_attributes]
                                        @config[:first_boot_attributes].merge(build_knifezero_attributes_for_node)
                                      else
                                        @config[:first_boot_attributes] = build_knifezero_attributes_for_node
                                      end
  end

  File.open(client_builder.client_path, 'w') do |f|
    f.puts OpenSSL::PKey::RSA.new(2048).to_s
  end
  super
end

#validate_options!Object

For support policy_document_databag(old style)



95
96
97
98
99
100
101
# File 'lib/chef/knife/zero_bootstrap.rb', line 95

def validate_options!
  if policyfile_and_run_list_given?
    ui.error('Policyfile options and --run-list are exclusive')
    exit 1
  end
  true
end