lita-puppet 0.5.4 → 0.5.5

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: 76d165987e3bcb1bfa1f04645a372db05bbabb95
4
- data.tar.gz: aad95487e3aa635215f82698f19d4783bddf0f76
3
+ metadata.gz: 71652e9e43f1a190a33ffe04320e3f89521668bb
4
+ data.tar.gz: 43e091d0e1701c4061a76ac6f497f34b57f58f9f
5
5
  SHA512:
6
- metadata.gz: 2a66a02659ea330d95fea211ea66f9e6e93039a3cc37ff76e9153cf2fff572814069edc6cdfdee43fed6650dc8c1ab0082c254a6d247ad60b5eaeebd4466111d
7
- data.tar.gz: 34e3b651c329184589c4ccef2b6251c89c53a99271a6e24b52e2a1c5024785426776e718da889b0d1825cebf3276ef56b57a1c65397ba402758bb75b93d558e4
6
+ metadata.gz: 6de78f5ca3101630efe3a9634b2fb45432c737afc73edb6a33fd91b945edf2285a84380ca1cc3010438142ddebd806fd522d270d1929e09da2dd3b69430e426d
7
+ data.tar.gz: 6cb0e7853f81ce64e3eaf8e602f4450600259d22b1bfc9b0aa6a139c720c6aa10e1d09a9cb4901408f0f6dc85d0cb5cb7f24645193c39296ec9a5fc592007343
data/README.md CHANGED
@@ -12,9 +12,10 @@ gem "lita-puppet"
12
12
 
13
13
  ## Configuration
14
14
 
15
+ * `config.handlers.puppet.control_repo_path` - Path for `git pull` during r10k deployments
15
16
  * `config.handlers.puppet.master_hostname` - Puppet Master's hostname
17
+ * `config.handlers.puppet.puppetdb_url` - PuppetDB hostname (for the [puppetdb-ruby](https://github.com/voxpupuli/puppetdb-ruby) gem)
16
18
  * `config.handlers.puppet.ssh_user` - SSH user for the Puppet Master for r10k deployments
17
- * `config.handlers.puppet.control_repo_path` - Path for `git pull` during r10k deployments
18
19
 
19
20
  ## Usage
20
21
 
@@ -48,3 +49,14 @@ This is also available as:
48
49
  pp cert clean <host>
49
50
 
50
51
  **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.
52
+
53
+ #### Query PuppetDB for the Roles and Profiles used by a node
54
+ puppet catalog <certname> profiles
55
+
56
+ This is also available as:
57
+
58
+ puppet node <certname> profiles
59
+ pp catalog <certname> profiles
60
+ pp node <certname> profiles
61
+
62
+ Where `<certname>` is the SSL certificate name used for Puppet. This is usually the FQDN for the host.
@@ -34,6 +34,15 @@ module Lita
34
34
  }
35
35
  )
36
36
 
37
+ route(
38
+ /(puppet|pp)\s+(class)\s+(nodes)\s+(\S+)/i,
39
+ :nodes_with_class,
40
+ command: true,
41
+ help: {
42
+ "puppet class nodes <class>" => "Query PuppetDB to get a list of all nodes containing a class."
43
+ }
44
+ )
45
+
37
46
  route(
38
47
  /(puppet|pp)\s+(r10k|deploy)(\s+(\S+)(\s+(\S+))?)?/i,
39
48
  :r10k_deploy,
@@ -136,6 +145,31 @@ module Lita
136
145
  end
137
146
  end
138
147
 
148
+ def nodes_with_class(response)
149
+ puppet_class = response.matches[0][3]
150
+ url = config.puppetdb_url
151
+ username = friendly_name(response.user.name)
152
+
153
+ unless url
154
+ cant_reply = "#{username}, I would do that, but I don't know how to connect to PuppetDB."
155
+ cant_reply << "Edit my config and add `config.handlers.puppet.puppetdb_url`."
156
+ response.reply(cant_reply)
157
+ return false
158
+ end
159
+
160
+ response.reply("#{username}, let me see what I can find in PuppetDB for you.")
161
+
162
+ puppet_classes = class_nodes(url, puppet_class)
163
+ if puppet_classes.empty?
164
+ response.reply("There are no nodes with #{puppet_class} class, are you sure its a valid class?")
165
+ return false
166
+ else
167
+ response.reply("Here are all the nodes with class #{puppet_class}:")
168
+ response.reply("/code" + puppet_classes.join("\n"))
169
+ end
170
+ end
171
+
172
+
139
173
  def r10k_deploy(response)
140
174
  environment = response.matches[0][3]
141
175
  mod = response.matches[0][5]
@@ -19,5 +19,13 @@ module Utils
19
19
  # return all the tags related to profile:: or role::
20
20
  tags.sort.uniq.select {|t| t.match /^(profile|role)::/ }
21
21
  end
22
+
23
+ def class_nodes(url, classname)
24
+ client = ::PuppetDB::Client.new(server: url)
25
+ q = client.request('resources',[:and,[:'=','type', 'Class'],[:'=','title',"#{classname}"]])
26
+
27
+ q.data.map { |node| node['certname'] }
28
+ end
29
+
22
30
  end
23
31
  end
data/lita-puppet.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-puppet"
3
- spec.version = "0.5.4"
3
+ spec.version = "0.5.5"
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.5.4
4
+ version: 0.5.5
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-27 00:00:00.000000000 Z
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.5.1
169
+ rubygems_version: 2.4.8
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Allow the Lita bot to handle requests for puppet tasks