Sha256: cb6da1b51fe76e2ff366f84e9bb046389b1b4402e51ca20dbdd86313554a9f38
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
#! /usr/bin/env ruby # # handler-ansible.rb # # DESCRIPTION: # This handler runs an Ansible playbook (http://www.ansible.com/) passing the # check event as additional variables. # # Two settings are supported in ansible.json: # command : (optional) the ansible-playbook command # playbook : (required) the playbook to run # # Additionally, the playbook may be over ridden by the check definition.# # # OUTPUT: # # PLATFORMS: # Linux # # DEPENDENCIES: # gem: sensu-plugin # gem: json # # USAGE: # #YELLOW # # NOTES: # enable extended mod_status # # LICENSE: # Copyright 2014 Aaron Iles <aaron.iles@gmail.com> # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # require 'sensu-handler' require 'json' # # Ansible # class Ansible < Sensu::Handler def handle ansible = settings['ansible']['command'] || 'ansible-playbook' playbook = settings['ansible']['playbook'] || nil extra_vars = JSON.generate(@event) unless @event['check']['ansible'].nil? playbook = @event['check']['ansible']['playbook'] || playbook end command = "#{ansible} -e '#{extra_vars}' #{playbook}" output = `#{command}` if $CHILD_STATUS.exitstatus > 0 puts output exit 1 else puts "SUCCESS: #{command}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sensu-plugins-ansible-0.0.4 | bin/handler-ansible.rb |