puppet-pssh 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/puppet-pssh.rb +57 -6
- metadata +2 -2
data/lib/puppet-pssh.rb
CHANGED
@@ -4,10 +4,11 @@ require 'excon'
|
|
4
4
|
require 'json'
|
5
5
|
require 'logger'
|
6
6
|
require 'colored'
|
7
|
+
require 'pp'
|
7
8
|
|
8
9
|
module PuppetPSSH
|
9
10
|
|
10
|
-
VERSION = "0.
|
11
|
+
VERSION = "0.3"
|
11
12
|
|
12
13
|
if !defined? Log or Log.nil?
|
13
14
|
Log = Logger.new($stdout)
|
@@ -29,12 +30,16 @@ module PuppetPSSH
|
|
29
30
|
|
30
31
|
option ["-m", "--match"], "REGEX", "Only the nodes matching the regex", :default => '.*'
|
31
32
|
option ["-p", "--puppetmaster"], "PUPPETMASTER", "Puppet master host", :default => 'puppet'
|
32
|
-
option "--puppetmaster-port", "PUPPETMASTER_PORT", "Puppet master port", :default => '8080'
|
33
|
+
option ["-P", "--puppetmaster-port"], "PUPPETMASTER_PORT", "Puppet master port", :default => '8080'
|
33
34
|
option "--use-ssl", :flag, "Use SSL (https) to communicate with the puppetmaster", :default => false
|
34
35
|
option "--debug", :flag, "Print debugging output", :default => false do |o|
|
35
36
|
Log.level = Logger::DEBUG
|
36
37
|
end
|
37
38
|
|
39
|
+
def master_url
|
40
|
+
"#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/"
|
41
|
+
end
|
42
|
+
|
38
43
|
def get_nodes(puppetmaster)
|
39
44
|
url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes"
|
40
45
|
Log.debug "Puppet master host: #{puppetmaster}"
|
@@ -59,9 +64,50 @@ module PuppetPSSH
|
|
59
64
|
|
60
65
|
class List < BaseCommand
|
61
66
|
|
67
|
+
option ["-a", "--all-facts"], :flag, "Print node facts", :default => false
|
68
|
+
option ["-f", "--fact"], "FACT", "Print fact value"
|
69
|
+
option "--with-facts", "FACTS", "Comman separated list of facts to look for"
|
70
|
+
option "--status", :flag, "Print node status"
|
71
|
+
|
62
72
|
def execute
|
63
73
|
begin
|
64
|
-
get_nodes(puppetmaster).each
|
74
|
+
get_nodes(puppetmaster).each do |n|
|
75
|
+
next unless n =~ /#{match}/
|
76
|
+
if all_facts?
|
77
|
+
pp JSON.parse(Excon.get(master_url + "facts/#{n}").body)
|
78
|
+
elsif fact
|
79
|
+
value = JSON.parse(
|
80
|
+
Excon.get(master_url + "facts/#{n}").body
|
81
|
+
)['facts'][fact] || 'fact_not_found'
|
82
|
+
puts n
|
83
|
+
puts " #{fact.yellow}: " + value
|
84
|
+
elsif with_facts
|
85
|
+
facts = JSON.parse(
|
86
|
+
Excon.get(master_url + "facts/#{n}").body
|
87
|
+
)['facts']
|
88
|
+
keys = facts.keys
|
89
|
+
with_facts.split(',').each do |f|
|
90
|
+
if keys.include?(f)
|
91
|
+
puts n
|
92
|
+
break
|
93
|
+
end
|
94
|
+
end
|
95
|
+
elsif status?
|
96
|
+
puts n
|
97
|
+
status = JSON.parse(
|
98
|
+
Excon.get(master_url + "status/nodes/#{n}").body
|
99
|
+
)
|
100
|
+
puts " #{'name:'.ljust(20).yellow} #{status['name']}"
|
101
|
+
puts " #{'deactivated:'.ljust(20).yellow} " +
|
102
|
+
"#{status['deactivated'] || 'no'}"
|
103
|
+
puts " #{'catalog_timestamp:'.ljust(20).yellow} " +
|
104
|
+
"#{status['catalog_timestamp']}"
|
105
|
+
puts " #{'facts_timestamp:'.ljust(20).yellow} " +
|
106
|
+
"#{status['facts_timestamp']}"
|
107
|
+
else
|
108
|
+
puts n
|
109
|
+
end
|
110
|
+
end
|
65
111
|
rescue Exception => e
|
66
112
|
Log.error e.message
|
67
113
|
exit 1
|
@@ -162,9 +208,14 @@ module PuppetPSSH
|
|
162
208
|
Log.warn 'Disabled host key verification'
|
163
209
|
ssh_opts = '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
164
210
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
211
|
+
if nodes.empty?
|
212
|
+
Log.warn 'The node list is empty.'
|
213
|
+
Log.warn 'If you are using --match, the regexp didn\'t match any node.'
|
214
|
+
else
|
215
|
+
full_cmd = "#{pssh_path} #{extra_opts} -p #{threads} -o #{node_output_path} -t 300 -h #{hostlist_path} -x '#{ssh_opts}' " + "'#{command} 2>&1'"
|
216
|
+
Log.debug full_cmd
|
217
|
+
system full_cmd
|
218
|
+
end
|
168
219
|
end
|
169
220
|
end
|
170
221
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-pssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colored
|