Class: Lita::Handlers::Puppet
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Puppet
- Defined in:
- lib/lita/handlers/puppet.rb
Instance Method Summary collapse
Instance Method Details
#puppet_agent_run(response) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/lita/handlers/puppet.rb', line 71 def puppet_agent_run(response) host = response.matches[0][4] user = config.ssh_user || 'lita' username = response.user.name response.reply("#{username}, I'll run puppet right away. Give me a sec and I'll let you know how it goes.") ret = nil exception = nil # TODO: better error handling remote = Rye::Box.new(host, user: user, password_prompt: false) begin Timeout::timeout(300) do remote.cd '/tmp' # Need to use sudo from here on remote.enable_sudo # scary... remote.disable_safe_mode # build up the command command = 'puppet agent' command << ' --verbose --no-daemonize' command << ' --no-usecacheonfailure' command << ' --no-splay --show_diff' ret = remote.execute command end rescue Exception => e exception = e ensure remote.disconnect end # build a reply if ret response.reply "#{username}, that puppet run is complete! It exited with status #{ret.exit_status}." # Send the standard out, but strip off the bash color code stuff... response.reply "/code " + ret.stdout.join("\n").gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]/, '') else response.reply "#{username}, your puppet run is done, but didn't seem to work... I think it may have timed out." response.reply "/code " + exception. end end |
#r10k_deploy(response) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lita/handlers/puppet.rb', line 27 def r10k_deploy(response) environment = response.matches[0][3] control_repo = config.control_repo_path || '/opt/puppet/control' user = config.ssh_user || 'lita' username = response.user.name response.reply("#{username}, I'll get right on that. Give me a moment and I'll let you know how it went.") ret = nil # TODO: better error handling puppet_master = Rye::Box.new(config.master_hostname, user: user, password_prompt: false) begin Timeout::timeout(600) do puppet_master.cd control_repo # Need to use sudo from here on puppet_master.enable_sudo puppet_master.git :pull # scary... puppet_master.disable_safe_mode command = "r10k deploy environment" command << " #{environment}" if environment command << ' -pv' ret = puppet_master.execute command end rescue Exception => e exception = e ensure puppet_master.disconnect end # build a reply if ret response.reply("#{username}, your r10k deployment is done!") response.reply "/code " + ret.stderr.join("\n") else response.reply "#{username}, your r10k run didn't seem to work... I think it may have timed out." response.reply "/code " + exception. end end |