Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Fixes #16641 - fix after build hook to only delete client #54

Merged
merged 1 commit into from Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/lib/actions/foreman_chef/host/create.rb
Expand Up @@ -32,8 +32,10 @@ def plan(host)
# end

def finalize
if input[:create_action_output][:private_key].present?
::Host.find(self.input[:host][:id]).update_attribute(:chef_private_key, input[:create_action_output][:private_key])
if input[:create_action_output][:private_key].present? && Setting.validation_bootstrap_method
host = ::Host.find(self.input[:host][:id])
host.chef_private_key = input[:create_action_output][:private_key]
host.disable_dynflow_hooks { |h| h.save! }
end
end

Expand Down
13 changes: 12 additions & 1 deletion app/models/foreman_chef/concerns/host_build.rb
Expand Up @@ -6,7 +6,18 @@ module HostBuild
include ForemanTasks::Concerns::ActionSubject
include ForemanTasks::Concerns::ActionTriggering

after_build :plan_destroy_action
after_build do |host|
::ForemanTasks.sync_task ::Actions::ForemanChef::Client::Destroy, host.name, host.chef_proxy
# private key is no longer valid
host.chef_private_key = nil

if Setting.validation_bootstrap_method
new_client = ::ForemanTasks.sync_task ::Actions::ForemanChef::Client::Create, host.name, host.chef_proxy
host.chef_private_key = new_client.output[:private_key]
end

host.disable_dynflow_hooks { |h| h.save! }
end
end

end
Expand Down