94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/puppet-pssh.rb', line 94
def get_nodes(puppetmaster, include_deactivated = false)
query = URI.encode '["=", ["node", "active"], true]'
url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
Log.debug "Puppet master host: #{puppetmaster}"
Log.debug "Puppet master url: #{url}"
nodes = []
begin
out = Excon.get url
JSON.parse(out.body).each do |n|
next unless n =~ /#{match}/
nodes << n
end
if deactivated?
query = URI.encode '["=", ["node", "active"], false]'
url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
out = Excon.get url
JSON.parse(out.body).each do |n|
next unless n =~ /#{match}/
nodes << n
end
end
rescue TypeError => e
raise Exception.new "Error retrieving node list from master host: #{puppetmaster}"
rescue Excon::Errors::SocketError => e
raise Exception.new "Could not connect to the puppet master host: #{puppetmaster}"
end
nodes
end
|