Sha256: d0d03c3d8dc31227bf03356df10e79360ef2ee77823659f259b47eca59e9d150

Contents?: true

Size: 708 Bytes

Versions: 1

Compression:

Stored size: 708 Bytes

Contents

module Utils
  # Utility methods for working with PuppetDB
  module PuppetDB
    def dbquery(url, q)
      # TODO: validate incoming query structure
      client = ::PuppetDB::Client.new(server: url)
      client.request *q
    end

    def node_roles_and_profiles(url, nodename)
      # TODO: validate url and nodename
      ::PuppetDB::Client.new(server: url) # this is weird but required
      d = ::PuppetDB::Client.get("/catalogs/#{nodename}")
      return d["error"] if d['error']

      tags = []
      d["data"]["resources"].each {|r| tags.concat(r['tags'])}

      # return all the tags related to profile:: or role::
      tags.sort.uniq.select {|t| t.match /^(profile|role)::/ }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-puppet-0.5.4 lib/utils/puppetdb.rb