Ask Your Question

How to call upon puppet token that has just been generated to use to unpin nodes

asked 2017-11-13 22:49:21 -0500

athlonxl gravatar image
curl -k -X POST -H 'Content-Type: application/json' -d '{"login": "user", "password": "pass"}' https://server:4433/rbac-api/v1/auth/token

The command above i use to generate the token i need the next command uses it to run the following

curl -X POST -H 'Content-Type: application/json' -H "X-Authentication:$token" -d '{"nodes": ["foo.tld", "bar.tld", "baz.tld"]}' https://$HOSTNAME:4433/classifier-api/v1/commands/unpin-from-all

The problem I'm having is I have been manually inserting the token to unpin my nodes. I want to be able to call upon the token once its been generated in Linux so I don't have to copy and paste it every time. What command would i need to add to script to do this, if possible the same for the nodes.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-14 16:53:19 -0500

reesek gravatar image

updated 2017-11-14 16:55:59 -0500

This is an approach I've used.

#Generate a token
token=$(curl -X POST -H 'Content-Type: application/json' --cert $(/usr/local/bin/puppet config print hostcert) --key $(/usr/local/bin/puppet config print hostprivkey) --cacert $(/usr/local/bin/puppet config print localcacert) -d '{"login": "user", "password": "puppet", "lifetime": "10m"}' https://$(hostname -f):4433/rbac-api/v1/auth/token)

mkdir ~/.puppetlabs
echo $token | awk -F\" '{ print $4 }' > ~/.puppetlabs/token

# Deploy the production and vgt environment
curl -k -X POST -H 'Content-Type: application/json' -H "X-Authentication: `cat ~/.puppetlabs/token`" https://$(hostname -f):8170/code-manager/v1/deploys -d '{"environments": ["production", "vgt"], "wait": true}'
edit flag offensive delete link more


Thank you tried it out and worked great.

athlonxl gravatar imageathlonxl ( 2017-11-14 18:30:58 -0500 )edit

have you looked at 'jq'? you could use that (with its --raw or -r flag) instead of using awk for a order independent way of accessing the data inside of json output

DarylW gravatar imageDarylW ( 2017-11-15 08:17:17 -0500 )edit

DarylW - I've seen it, but the muscle memory always types awk ;) I'm going to have to give jq a try now. Thanks for the suggestion!

reesek gravatar imagereesek ( 2017-11-15 15:57:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-11-13 22:49:21 -0500

Seen: 30 times

Last updated: Nov 14 '17