puppet enterprise - How to automate adding a Node to a Group? -
i have switched puppet enterprise 3.8 pe 3.3. use use rake api create groups, classes , nodes. no longer works in pe 3.8 , there not appear documented way, other using dashboard (https://docs.puppetlabs.com/pe/latest/console_classes_groups.html#adding-nodes-to-a-node-group), add nodes given group.
can point me documentation of how 1 automates adding of nodes group?
you can use node classifier api add groups, or add nodes group. you'll need run these curl commands on master , include correct certs requests. in commands below, replace "fqdn" qualified domain name of master.
create group named "foo" child of default group
curl -x post -h 'content-type: application/json' \ --cert /etc/puppetlabs/puppet/ssl/certs/fqdn.pem \ --key /etc/puppetlabs/puppet/ssl/private_keys/fqdn.pem \ --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \ -d '{ "name": "foo", "parent": "00000000-0000-4000-8000-000000000000", "environment": "production", "classes": {} }' \ https://fqdn:4433/classifier-api/v1/groups
get groups can id of newly created group
curl 'https://fqdn:4433/classifier-api/v1/groups' \ -h "content-type: application/json" \ --cert /etc/puppetlabs/puppet/ssl/certs/fqdn.pem \ --key /etc/puppetlabs/puppet/ssl/private_keys/fqdn.pem \ --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem
the response request contain newly created group:
{ "environment_trumps": false, "parent": "00000000-0000-4000-8000-000000000000", "name": "foo", "variables": {}, "id": "085e2797-32f3-4920-9412-8e9decf4ef65", "environment": "production", "classes": {} },
modify new group "pin" node
curl -x post -h 'content-type: application/json' \ --cert /etc/puppetlabs/puppet/ssl/certs/fqdn.pem \ --key /etc/puppetlabs/puppet/ssl/private_keys/fqdn.pem \ --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \ -d '{ "rule": ["or", ["=", "name", "u38a.vm"]] }' \ https://fqdn:4433/classifier-api/v1/groups/085e2797-32f3-4920-9412-8e9decf4ef65
modify new group "pin" node (you must supply complete new rule)
curl -x post -h 'content-type: application/json' \ --cert /etc/puppetlabs/puppet/ssl/certs/fqdn.pem \ --key /etc/puppetlabs/puppet/ssl/private_keys/fqdn.pem \ --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \ -d '{ "rule": ["or", ["=", "name", "u38a.vm"], ["=", "name", "u38.vm"]] }' \ https://fqdn:4433/classifier-api/v1/groups/085e2797-32f3-4920-9412-8e9decf4ef65
update 2016-04-12
as of puppet enterprise 2016.1.1 can use new pin/unpin endpoints of classifier api more easily:
to pin nodes
curl -x post -h 'content-type: application/json' \ --cert $(puppet config print hostcert) \ --key $(puppet config print hostprivkey) \ --cacert $(puppet config print localcacert) \ -d '{"nodes": ["foo.tld", "bar.tld", "baz.tld"]}' \ https://$hostname:4433/classifier-api/v1/groups/<group id>/pin
to unpin nodes
curl -x post -h 'content-type: application/json' \ --cert $(puppet config print hostcert) \ --key $(puppet config print hostprivkey) \ --cacert $(puppet config print localcacert) \ -d '{"nodes": ["foo.tld", "bar.tld", "baz.tld"]}' \ https://$hostname:4433/classifier-api/v1/groups/<group id>/unpin
to unpin nodes groups
use new (tech preview) commands/unpin-from-all
endpoint:
curl -x post -h 'content-type: application/json' \ --cert $(puppet config print hostcert) \ --key $(puppet config print hostprivkey) \ --cacert $(puppet config print localcacert) \ -d '{"nodes": ["foo.tld", "bar.tld", "baz.tld"]}' \ https://$hostname:4433/classifier-api/v1/commands/unpin-from-all
with of these endpoints, can generate token , supply rather using cert-based auth.
Comments
Post a Comment