def safe_apply
unless @allow_user_apply
if ENV.fetch('USER') != 'root'
@skip_apply = true
@skip_apply_reason = '[**user is not root**]' unless @skip_apply_reason
end
end
action = @description.split("\n")[0]
if @skip_apply
@applied_status = :skipped
info( "(Skipping apply#{skip_apply_reason})", [status_color, :BOLD], " #{action}" )
else
info( ">> Applying:", [:GREEN, :BOLD], " #{action}... " )
debug('')
begin
apply
info( "#{@applied_status.to_s.capitalize}", [status_color, :BOLD] )
if @applied_status == :failed
if @die_on_apply_fail
raise apply_summary
else
pause(:error)
end
end
rescue EOFError, SignalException => e
raise
rescue InternalError => e
raise "Internal error: {e.message}"
rescue Exception => e
@applied_status = :failed
error( "#{@applied_status.to_s.capitalize}:", [status_color, :BOLD] )
error( "#{e.message.to_s.gsub( /^/, ' ' )}", [status_color] )
raise e if @die_on_apply_fail
end
end
@applied_time = Time.now
end