lita-puppet 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc01d182f59a053388f0ebbab4e0dc6212b7ef18
4
- data.tar.gz: 96d3ec8b6c30c7d32eec8511a4a08dc1afdb739a
3
+ metadata.gz: 3c1150a88c8b08a9520d3a28a724d5a12c58ee9f
4
+ data.tar.gz: 5c25d159b9492928484993df6a3736a79cbfb344
5
5
  SHA512:
6
- metadata.gz: 779595d2a15c640e635bb7598023e4a66d98d3b285e20a347e5622fc4b3f8288c7c5dc889a3d5e02654c19e8a6db0b8786233d16bb8bd8103197da6100c3ce25
7
- data.tar.gz: 826ed7a4fddfdb30dca4e0021fda54305d6f101a0929451c1107320bd9a48b4df5d3ffbefb30e1f4e420edc4cf8113b8c545d125b0d445b96e361c4c2e27bf40
6
+ metadata.gz: 19e33adbed14606f8a02f54cb69f21c5c15dfde377145e1779c1b5c8099f327d2b3ecb3d5f278407c9bcb0b69fe1ec3f36eec6eceadada268e5fc9178cd91777
7
+ data.tar.gz: 362c3195f6d0ae7fb4441eb0d4edf9dff91ad17a04496b85131bd2a3fd7569014e923227474e7f209bf1fae1fd5ca4fff0ee226965c9557f065d79133f9a7c96
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # lita-puppet
2
2
 
3
- TODO: Add a description of the plugin.
3
+ A [Lita](https://www.lita.io/) handler plugin for some basic [Puppet](https://puppet.com/) operations.
4
4
 
5
5
  ## Installation
6
6
 
@@ -26,3 +26,25 @@ This is also available as:
26
26
  puppet deploy [environment]
27
27
  pp deploy [environment]
28
28
  pp r10k [environment]
29
+
30
+ #### Trigger a manual run of the Puppet agent on a host
31
+ puppet agent run on <host>
32
+
33
+ This is also available as:
34
+
35
+ puppet run on <host>
36
+ puppet run <host>
37
+ pp agent run on <host>
38
+ pp run on <host>
39
+ pp on <host>
40
+
41
+ Though we don't recomend that last one...
42
+
43
+ #### Remove an SSL cert from the Puppet Master
44
+ puppet cert clean <host>
45
+
46
+ This is also available as:
47
+
48
+ pp cert clean <host>
49
+
50
+ **Note** though that this doesn't do anything on the client side. If you want puppet to work on the `<host>` machine you'll need to generate a new cert. Usually you run this if you're planning to do that anyway though.
@@ -7,67 +7,61 @@ module Lita
7
7
  config :control_repo_path, required: false, type: String
8
8
 
9
9
  route(
10
- /(puppet|pp)\s+(r10k|deploy)(\s(\S+))?/i,
11
- :r10k_deploy,
10
+ /(puppet|pp)(\s+agent)?\s+(run)(\s+on)?\s+(\S+)/i,
11
+ :puppet_agent_run,
12
12
  command: true,
13
13
  help: {
14
- "puppet r10k [env]" => "Deploy the latest puppet code on the puppet master via r10k, optionally specifying an environment."
14
+ "puppet agent run on <host>" => "Run the puppet agent on <host>."
15
15
  }
16
16
  )
17
17
 
18
18
  route(
19
- /(puppet|pp)(\s+agent)?\s+(run)(\s+on)?\s(\S+)/i,
20
- :puppet_agent_run,
19
+ /(puppet|pp)\s+(cert)\s+(clean)\s+(\S+)/i,
20
+ :cert_clean,
21
21
  command: true,
22
22
  help: {
23
- "puppet agent run on <host>" => "Run the puppet agent on <host>."
23
+ "puppet cert clean <host>" => "Remove all traces of the SSL cert for <host> on the Puppet Master."
24
+ }
25
+ )
26
+
27
+ route(
28
+ /(puppet|pp)\s+(r10k|deploy)(\s+(\S+))?/i,
29
+ :r10k_deploy,
30
+ command: true,
31
+ help: {
32
+ "puppet r10k [env]" => "Deploy the latest puppet code on the puppet master via r10k, optionally specifying an environment."
24
33
  }
25
34
  )
26
35
 
27
36
  include ::Utils::SSH
28
37
  include ::Utils::Text
29
38
 
30
- def r10k_deploy(response)
31
- environment = response.matches[0][3]
32
- control_repo = config.control_repo_path || '/opt/puppet/control'
39
+ def cert_clean(response)
40
+ cert = response.matches[0][3]
33
41
  user = config.ssh_user || 'lita'
34
42
  username = friendly_name(response.user.name)
35
43
 
36
- response.reply("#{username}, I'll get right on that. Give me a moment and I'll let you know how it went.")
37
-
38
- result1 = over_ssh(host: config.master_hostname, user: user, timeout: 120) do |server|
39
- # Need to use sudo
40
- server.enable_sudo
41
- server[control_repo].git :pull
42
- end
43
-
44
- if result1[:exception]
45
- response.reply "#{username}, your r10k run didn't seem to work. Looks like there was a problem with Git:"
46
- response.reply "/code " + result1[:exception].message
47
- raise result1[:exception]
48
- end
44
+ response.reply("#{username}, working on that `puppet cert clean`. I'll get right back to you.")
49
45
 
50
- result2 = over_ssh(host: config.master_hostname, user: user) do |server|
46
+ result = over_ssh(host: config.master_hostname, user: user, timeout: 120) do |server|
47
+ server.cd '/tmp'
51
48
  # Need to use sudo
52
49
  server.enable_sudo
53
50
  # scary...
54
51
  server.disable_safe_mode
55
52
 
56
- command = "r10k deploy environment"
57
- command << " #{environment}" if environment
58
- command << ' -pv'
59
- server.execute command
53
+ server.execute "puppet cert clean #{cert}"
60
54
  end
61
55
 
62
- if result2[:exception]
63
- response.reply "#{username}, your r10k run didn't seem to work... Maybe it timed out?"
64
- response.reply "/code " + result2[:exception].message
65
- raise result2[:exception]
56
+ if result[:exception]
57
+ response.reply "#{username}, your `puppet cert clean` didn't seem to work... ;-("
58
+ response.reply "/code " + result[:exception].message
59
+ raise result[:exception]
66
60
  end
67
61
 
68
62
  # build a reply
69
- response.reply("#{username}, your r10k deployment is done!")
70
- reply_content = [result1[:stdout].join("\n"), result2[:stderr].join("\n")].join("\n")
63
+ response.reply("#{username}, your `puppet cert clean` is all done!")
64
+ reply_content = [result[:stdout].join("\n"), result[:stderr].join("\n")].join("\n")
71
65
  response.reply "/code " + sanitze_for_chat(reply_content)
72
66
  end
73
67
 
@@ -107,6 +101,50 @@ module Lita
107
101
  end
108
102
  end
109
103
 
104
+ def r10k_deploy(response)
105
+ environment = response.matches[0][3]
106
+ control_repo = config.control_repo_path || '/opt/puppet/control'
107
+ user = config.ssh_user || 'lita'
108
+ username = friendly_name(response.user.name)
109
+
110
+ response.reply("#{username}, I'll get right on that. Give me a moment and I'll let you know how it went.")
111
+
112
+ result1 = over_ssh(host: config.master_hostname, user: user, timeout: 120) do |server|
113
+ # Need to use sudo
114
+ server.enable_sudo
115
+ server[control_repo].git :pull
116
+ end
117
+
118
+ if result1[:exception]
119
+ response.reply "#{username}, your r10k run didn't seem to work. Looks like there was a problem with Git:"
120
+ response.reply "/code " + result1[:exception].message
121
+ raise result1[:exception]
122
+ end
123
+
124
+ result2 = over_ssh(host: config.master_hostname, user: user) do |server|
125
+ # Need to use sudo
126
+ server.enable_sudo
127
+ # scary...
128
+ server.disable_safe_mode
129
+
130
+ command = "r10k deploy environment"
131
+ command << " #{environment}" if environment
132
+ command << ' -pv'
133
+ server.execute command
134
+ end
135
+
136
+ if result2[:exception]
137
+ response.reply "#{username}, your r10k run didn't seem to work... Maybe it timed out?"
138
+ response.reply "/code " + result2[:exception].message
139
+ raise result2[:exception]
140
+ end
141
+
142
+ # build a reply
143
+ response.reply("#{username}, your r10k deployment is done!")
144
+ reply_content = [result1[:stdout].join("\n"), result2[:stderr].join("\n")].join("\n")
145
+ response.reply "/code " + sanitze_for_chat(reply_content)
146
+ end
147
+
110
148
  Lita.register_handler(self)
111
149
  end
112
150
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-puppet"
3
- spec.version = "0.3.1"
3
+ spec.version = "0.4.0"
4
4
  spec.authors = ["Jonathan Gnagy"]
5
5
  spec.email = ["jgnagy@knuedge.com"]
6
6
  spec.description = "Some basic Puppet interactions for Lita"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita