lib/chef/knife/client_create.rb in chef-0.10.4 vs lib/chef/knife/client_create.rb in chef-0.10.6.beta.1
- old
+ new
@@ -53,19 +53,25 @@
client.name(@client_name)
client.admin(config[:admin])
output = edit_data(client)
- key = output.save
+ # Chef::ApiClient.save will try to create a client and if it exists will update it instead silently
+ client = output.save
- ui.info("Created #{output}")
-
- if config[:file]
- File.open(config[:file], "w") do |f|
- f.print(key['private_key'])
+ # We only get a private_key on client creation, not on client update.
+ if client['private_key']
+ ui.info("Created #{output}")
+
+ if config[:file]
+ File.open(config[:file], "w") do |f|
+ f.print(client['private_key'])
+ end
+ else
+ puts client['private_key']
end
else
- puts key['private_key']
+ ui.error "Client '#{client['name']}' already exists"
end
end
end
end
end