Last active
August 29, 2015 14:12
-
-
Save acidprime/316862a7dc375bab90e3 to your computer and use it in GitHub Desktop.
Sync r10k then run puppet on respective environment on agents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/puppet/bin/ruby | |
require 'mcollective' | |
require 'yaml' | |
include MCollective::RPC | |
WEBHOOK_CONFIG = '/etc/webhook.yaml' | |
ENV['HOME'] = '/var/lib/peadmin' | |
ENV['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin:/opt/puppet/bin' | |
if (File.exists?(WEBHOOK_CONFIG)) | |
$config = YAML.load_file(WEBHOOK_CONFIG) | |
else | |
raise "Configuration file: #{WEBHOOK_CONFIG} does not exist" | |
end | |
def mco(branch) | |
options = MCollective::Util.default_options | |
options[:config] = $config['client_cfg'] | |
client = rpcclient('r10k', :exit_on_failure => false,:options => options) | |
client.discovery_timeout = $config['discovery_timeout'].to_i | |
client.timeout = $config['client_timeout'].to_i | |
result = client.send('deploy',{:environment => branch}) | |
end # end deploy() | |
def puppet(environment) | |
options = MCollective::Util.default_options | |
options[:config] = $config['client_cfg'] | |
options[:fact] = {:fact => 'r10k_environment', :value => "#{environment}",:operator => '==' } | |
client = rpcclient('puppet', :exit_on_failure => false,:options => options) | |
client.discovery_timeout = $config['discovery_timeout'].to_i | |
client.timeout = $config['client_timeout'].to_i | |
#result = client.send('runonce') | |
result = client.custom_request('runonce',{},client.discover,{:fact => "r10k_environment=#{environment}"}) | |
end # end deploy() | |
r10k_result = mco(ARGV[0]).first | |
if r10k_result.results[:statuscode] == 0 | |
message = r10k_result.results[:statusmsg] | |
else | |
raise r10k_result.results[:statusmsg] | |
end | |
puts message | |
puppet_result = puppet(ARGV[0]) | |
puts puppet_result.inspect | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment