{"id":15022612,"url":"https://github.com/puppetlabs/puppet-classify","last_synced_at":"2025-04-06T03:09:52.641Z","repository":{"id":22692567,"uuid":"26036415","full_name":"puppetlabs/puppet-classify","owner":"puppetlabs","description":"A ruby library to interface with the classifier service","archived":false,"fork":false,"pushed_at":"2025-02-04T02:15:28.000Z","size":83,"stargazers_count":17,"open_issues_count":3,"forks_count":16,"subscribers_count":157,"default_branch":"master","last_synced_at":"2025-03-30T02:07:27.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puppetlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-31T23:20:44.000Z","updated_at":"2024-09-05T18:07:53.000Z","dependencies_parsed_at":"2024-06-21T02:11:44.670Z","dependency_job_id":"7d5b75df-8554-4a21-858d-907989a7eb1c","html_url":"https://github.com/puppetlabs/puppet-classify","commit_stats":{"total_commits":74,"total_committers":10,"mean_commits":7.4,"dds":"0.28378378378378377","last_synced_commit":"78fea4c14e07c36a011029935a4573673712c474"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppet-classify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppet-classify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppet-classify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppet-classify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puppetlabs","download_url":"https://codeload.github.com/puppetlabs/puppet-classify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:58:12.140Z","updated_at":"2025-04-06T03:09:52.620Z","avatar_url":"https://github.com/puppetlabs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# puppet classify\n\nA ruby library to interface with the classifier service\n\n[![Gem Version](https://badge.fury.io/rb/puppetclassify.svg)](https://badge.fury.io/rb/puppetclassify)\n\n## How to install\n\n```\ngem install puppetclassify\n```\n\n### Locally\n\n```\ngem build puppetclassify.gemspec\ngem install puppetclassify-0.1.0.gem\n```\n\n## Maintenance\n\nMaintainers: [Puppet](https://github.com/puppetlabs)\n\nTickets: Open an issue or pull request directly on this repository\n\n## How to use\n\nHere is the basic configuration you'll need to use the puppetclassify class with certificate auth:\n\n```ruby\nrequire 'puppetclassify'\n# URL of classifier as well as certificates and private key for auth\nauth_info = {\n  \"ca_certificate_path\" =\u003e \"/etc/puppetlabs/puppet/ssl/certs/ca.pem\",\n  \"certificate_path\"    =\u003e \"/etc/puppetlabs/puppet/ssl/certs/myhostname.vm.pem\",\n  \"private_key_path\"    =\u003e \"/etc/puppetlabs/puppet/ssl/private_keys/myhostname.vm.pem\",\n  \"read_timeout\"        =\u003e 90 # optional timeout, defaults to 90 if this key doesn't exist\n}\n\nclassifier_url = 'https://puppetmaster.local:4433/classifier-api'\npuppetclassify = PuppetClassify.new(classifier_url, auth_info)\n```\n\nYou can also use token auth by either supplying a path to a token file:\n\n```ruby\nauth_info = {\n  \"ca_certificate_path\" =\u003e \"/etc/puppetlabs/puppet/ssl/certs/ca.pem\",\n  \"token_path\"          =\u003e \"/home/sam/.puppetlabs/token\",\n}\n```\n\nOr by specifying a token string directly:\n\n```ruby\ntoken = 'eyJhbGciOiJSUzUxM....'\nauth_info = {\n  \"ca_certificate_path\" =\u003e \"/etc/puppetlabs/puppet/ssl/certs/ca.pem\",\n  \"token\"               =\u003e token,\n}\n```\n\nIf you have a token file at `~/.puppetlabs/token` then you can make use of it by not specifying any authentication info, ie:\n\n```ruby\nauth_info = {\n  \"ca_certificate_path\" =\u003e \"/etc/puppetlabs/puppet/ssl/certs/ca.pem\",\n}\n```\n\n### Basic case\n\nIf you are wanting to get all of the groups the classifier knows about:\n\n```ruby\n# Get all the groups\npuppetclassify.groups.get_groups\n```\n\n### Taking action on a specific group by name\n\nIf you have a group you want to modify, but do not know the group ID:\n\n```ruby\nmy_group_id = puppetclassify.groups.get_group_id(\"My Group Name\")\ngroup_delta = {\"variables\"=\u003e{\"key\"=\u003e\"value\"}, \"id\"=\u003emy_group_id, \"classes\"=\u003e{\"motd\"=\u003e{\"content\"=\u003e\"hello!\"}}} # an example to update a groups variables and classes\npuppetclassify.groups.update_group(group_delta)\n```\n\n### Retrieving classification of a node\n\nBecause the Console classifies nodes based on rules, you may want to submit a\ncomplete `facts` hash for rules to match. See [the API docs](https://docs.puppetlabs.com/pe/latest/nc_classification.html)\nfor examples.\n\nYou can retrieve facts for the local node either using Facter from Ruby or the\ncommand line. For example:\n\n```ruby\n#! /opt/puppetlabs/puppet/bin/ruby\nrequire 'facter'\n\nfacts = { 'fact' =\u003e Facter.to_hash }\n```\n\nor:\n\n```ruby\n#! /usr/bin/env ruby\nrequire 'json'\n\nfacts = { 'fact' =\u003e JSON.parse(`facter -j`) }\n```\n\nOnce you have the facts, retrieving classification of a node is simple:\n\n```ruby\n#! /opt/puppetlabs/puppet/bin/ruby\nrequire 'facter'\nrequire 'puppetclassify'\n\n# NOTE: Add setup information here for puppetclassify\n\n# gather facts\nfacts = { 'fact' =\u003e Facter.to_hash }\n\n# Get a node's classification\npuppetclassify.classification.get('myhostname.puppetlabs.vm', facts)\n```\n\n### Pinning and unpinning nodes to a group in Puppet enterprise\n\nIf you want to \"pin\" a node to a specific group so it gets that classification, you can\ninvoke the pin_nodes command. And if you want to remove nodes from that group, you can run\nthe unpin_nodes command.\n\nIf you want to remove nodes from every group they are pinned to, use the unpin_from_all command.\n\n```ruby\nmy_group_id = puppetclassify.groups.get_group_id(\"My Super Awesome Group Name\")\n\nnodes = [\"hostname.com\", \"myotherhost.com\", \"anotherhost.com\"]\n# pin nodes to group\npuppetclassify.groups.pin_nodes(my_group_id, nodes)\n\n# unpin nodes from group\npuppetclassify.groups.unpin_nodes(my_group_id, nodes)\n\n# unpin nodes from EVERY group\npuppetclassify.commands.unpin_from_all(nodes)\n```\n\n## Library Docs\n\n[rubydoc](http://www.rubydoc.info/gems/puppetclassify/0.1.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppet-classify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuppetlabs%2Fpuppet-classify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppet-classify/lists"}