lita-puppet 0.4.5 → 0.5.4

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: 5c57852a191a5435265de21bc2edc1d675a5d1ae
4
- data.tar.gz: 1f5791d60f1c91962086a6a6e9fb41181468d6ce
3
+ metadata.gz: 76d165987e3bcb1bfa1f04645a372db05bbabb95
4
+ data.tar.gz: aad95487e3aa635215f82698f19d4783bddf0f76
5
5
  SHA512:
6
- metadata.gz: cdd81a81ca7718ce7fab03d8d761c82672531b45c80789fe3435f52d77a13792ba5e95297963cfbbe38a83f74d1b05dd5698d6dfd8011b0a156e6d92955abd1c
7
- data.tar.gz: 6d508d6095fa6b1cf3360d02560fbce456be962490c0cd85da28cbfc435c7c6475fcbc14a7d1d465d0c7abcf3262c98d0de092a94017e461f7bf252a9f22e04c
6
+ metadata.gz: 2a66a02659ea330d95fea211ea66f9e6e93039a3cc37ff76e9153cf2fff572814069edc6cdfdee43fed6650dc8c1ab0082c254a6d247ad60b5eaeebd4466111d
7
+ data.tar.gz: 34e3b651c329184589c4ccef2b6251c89c53a99271a6e24b52e2a1c5024785426776e718da889b0d1825cebf3276ef56b57a1c65397ba402758bb75b93d558e4
@@ -5,6 +5,7 @@ module Lita
5
5
  config :master_hostname, required: true, type: String
6
6
  config :ssh_user, required: false, type: String
7
7
  config :control_repo_path, required: false, type: String
8
+ config :puppetdb_url, required: false, type: String
8
9
 
9
10
  route(
10
11
  /(puppet|pp)(\s+agent)?\s+(run)(\s+on)?\s+(\S+)/i,
@@ -24,6 +25,15 @@ module Lita
24
25
  }
25
26
  )
26
27
 
28
+ route(
29
+ /(puppet|pp)\s+(catalog|node)\s+(\S+)\s+(profiles)/i,
30
+ :node_profiles,
31
+ command: true,
32
+ help: {
33
+ "puppet catalog <host> profiles" => "Query PuppetDB to get a list of all roles and profiles applied to <host>."
34
+ }
35
+ )
36
+
27
37
  route(
28
38
  /(puppet|pp)\s+(r10k|deploy)(\s+(\S+)(\s+(\S+))?)?/i,
29
39
  :r10k_deploy,
@@ -33,6 +43,7 @@ module Lita
33
43
  }
34
44
  )
35
45
 
46
+ include ::Utils::PuppetDB
36
47
  include ::Utils::SSH
37
48
  include ::Utils::Text
38
49
 
@@ -101,6 +112,30 @@ module Lita
101
112
  end
102
113
  end
103
114
 
115
+ def node_profiles(response)
116
+ host = response.matches[0][2]
117
+ url = config.puppetdb_url
118
+ username = friendly_name(response.user.name)
119
+
120
+ unless url
121
+ cant_reply = "#{username}, I would do that, but I don't know how to connect to PuppetDB."
122
+ cant_reply << "Edit my config and add `config.handlers.puppet.puppetdb_url`."
123
+ response.reply(cant_reply)
124
+ return false
125
+ end
126
+
127
+ response.reply("#{username}, let me see what I can find in PuppetDB for you.")
128
+
129
+ profiles = node_roles_and_profiles(url, host)
130
+ if profiles.is_a? String
131
+ response.reply("Hmmm, that didn't work. Here's what PuppetDB responded with: '#{profiles}'")
132
+ return false
133
+ else
134
+ response.reply("Here are the profiles and roles for #{host}:")
135
+ response.reply("/code" + profiles.join("\n"))
136
+ end
137
+ end
138
+
104
139
  def r10k_deploy(response)
105
140
  environment = response.matches[0][3]
106
141
  mod = response.matches[0][5]
data/lib/lita-puppet.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require "lita"
2
2
  require 'rye'
3
3
  require 'timeout'
4
+ require 'puppetdb'
4
5
 
5
6
  Lita.load_locales Dir[File.expand_path(
6
7
  File.join("..", "..", "locales", "*.yml"), __FILE__
7
8
  )]
8
9
 
10
+ require 'utils/puppetdb'
9
11
  require 'utils/ssh'
10
12
  require 'utils/text'
11
13
  require "lita/handlers/puppet"
@@ -0,0 +1,23 @@
1
+ module Utils
2
+ # Utility methods for working with PuppetDB
3
+ module PuppetDB
4
+ def dbquery(url, q)
5
+ # TODO: validate incoming query structure
6
+ client = ::PuppetDB::Client.new(server: url)
7
+ client.request *q
8
+ end
9
+
10
+ def node_roles_and_profiles(url, nodename)
11
+ # TODO: validate url and nodename
12
+ ::PuppetDB::Client.new(server: url) # this is weird but required
13
+ d = ::PuppetDB::Client.get("/catalogs/#{nodename}")
14
+ return d["error"] if d['error']
15
+
16
+ tags = []
17
+ d["data"]["resources"].each {|r| tags.concat(r['tags'])}
18
+
19
+ # return all the tags related to profile:: or role::
20
+ tags.sort.uniq.select {|t| t.match /^(profile|role)::/ }
21
+ end
22
+ end
23
+ 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.4.5"
3
+ spec.version = "0.5.4"
4
4
  spec.authors = ["Jonathan Gnagy"]
5
5
  spec.email = ["jgnagy@knuedge.com"]
6
6
  spec.description = "Some basic Puppet interactions for Lita"
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_runtime_dependency "lita", "~> 4.7"
18
18
  spec.add_runtime_dependency "rye"
19
+ spec.add_runtime_dependency "puppetdb-ruby"
19
20
 
20
21
  spec.add_development_dependency "bundler", "~> 1.3"
21
22
  spec.add_development_dependency "pry-byebug"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puppetdb-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +137,7 @@ files:
123
137
  - Rakefile
124
138
  - lib/lita-puppet.rb
125
139
  - lib/lita/handlers/puppet.rb
140
+ - lib/utils/puppetdb.rb
126
141
  - lib/utils/ssh.rb
127
142
  - lib/utils/text.rb
128
143
  - lita-puppet.gemspec