Commit ae416e7f authored by Albert Vaca Cintora's avatar Albert Vaca Cintora
Browse files

Do not try to delete things that don't exist

Fixes:
FATAL: Chef::Exceptions::ResourceNotFound: Cannot find a resource matching windows_env[DDAGENTUSER_NAME] (did you define it first?)
parent c51b7ed5
......@@ -19,38 +19,34 @@
include_recipe 'chef_handler'
dd_agent_flavor = Chef::Datadog.agent_flavor(node)
if dd_agent_flavor != 'datadog-agent'
raise "Unsupported agent flavor '#{dd_agent_flavor}' on Windows (only supports 'datadog-agent')"
end
module Windows
class Helper
def do_cleanup(context)
Chef::Log.info 'Windows environment vars cleanup started.'
def clean_user(context)
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_NAME]')
resource.run_action(:delete) if resource
resource.run_action(:delete)
end
def clean_password(context)
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_PASSWORD]')
resource.run_action(:delete) if resource
Chef::Log.info 'Windows environment vars cleanup finished.'
resource.run_action(:delete)
end
end
end
Chef.event_handler do
on :run_failed do
Windows::Helper.new.do_cleanup(
Chef.run_context
)
end
end
dd_agent_version = Chef::Datadog.agent_version(node)
dd_agent_flavor = Chef::Datadog.agent_flavor(node)
if dd_agent_flavor != 'datadog-agent'
raise "Unsupported agent flavor '#{dd_agent_flavor}' on Windows (only supports 'datadog-agent')"
end
ddagentuser_name = Chef::Datadog.ddagentuser_name(node)
ddagentuser_password = Chef::Datadog.ddagentuser_password(node)
if ddagentuser_name
Chef.event_handler do
on :run_failed do
Windows::Helper.new.clean_user(Chef.run_context)
end
end
windows_env 'DDAGENTUSER_NAME' do
value ddagentuser_name
sensitive true
......@@ -58,12 +54,19 @@ if ddagentuser_name
end
if ddagentuser_password
Chef.event_handler do
on :run_failed do
Windows::Helper.new.clean_password(Chef.run_context)
end
end
windows_env 'DDAGENTUSER_PASSWORD' do
value ddagentuser_password
sensitive true
end
end
dd_agent_version = Chef::Datadog.agent_version(node)
if dd_agent_version.nil?
# Use latest
agent_major_version = Chef::Datadog.agent_major_version(node)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment