Class: PuppetPSSH::List

Inherits:
BaseCommand show all
Defined in:
lib/puppet-pssh.rb

Instance Method Summary collapse

Methods inherited from BaseCommand

#get_nodes, #master_url

Instance Method Details

#executeObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/puppet-pssh.rb', line 72

def execute
  begin
    get_nodes(puppetmaster).each do |n| 
      next unless n =~ /#{match}/
      if all_facts?
        pp JSON.parse(Excon.get(master_url + "facts/#{n}").body)
      elsif fact
        value = JSON.parse(
          Excon.get(master_url + "facts/#{n}").body
        )['facts'][fact] || 'fact_not_found'
        puts n 
        puts "  #{fact.yellow}: " + value
      elsif with_facts
        facts = JSON.parse(
          Excon.get(master_url + "facts/#{n}").body
        )['facts']
        keys = facts.keys
        with_facts.split(',').each do |f|
          if keys.include?(f)
            puts n
            break
          end
        end
      elsif status?
        puts n
        status = JSON.parse(
          Excon.get(master_url + "status/nodes/#{n}").body
        )
        puts "  #{'name:'.ljust(20).yellow} #{status['name']}"
        puts "  #{'deactivated:'.ljust(20).yellow} " +
             "#{status['deactivated'] || 'no'}"
        puts "  #{'catalog_timestamp:'.ljust(20).yellow} " + 
             "#{status['catalog_timestamp']}"
        puts "  #{'facts_timestamp:'.ljust(20).yellow} " + 
             "#{status['facts_timestamp']}"
      else
        puts n 
      end
    end
  rescue Exception => e
    Log.error e.message
    exit 1
  end
end