Skip to content

Instantly share code, notes, and snippets.

@velocity303
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save velocity303/431ed7030462229a07c3 to your computer and use it in GitHub Desktop.

Select an option

Save velocity303/431ed7030462229a07c3 to your computer and use it in GitHub Desktop.
set_classif.sh
#!/bin/bash
# simple 3.7 NC classifier commands
declare -x PE_CERT=$(/opt/puppet/bin/puppet agent --configprint hostcert)
declare -x PE_KEY=$(/opt/puppet/bin/puppet agent --configprint hostprivkey)
declare -x PE_CA=$(/opt/puppet/bin/puppet agent --configprint localcacert)
declare -x PE_CERTNAME=$(/opt/puppet/bin/puppet agent --configprint certname)
declare -x NC_CURL_OPT="-s --cacert $PE_CA --cert $PE_CERT --key $PE_KEY --insecure"
find_guid()
{
echo $(curl $NC_CURL_OPT --insecure https://localhost:4433/classifier-api/v1/groups| python -m json.tool |grep -C 2 "$1" | grep "id" | cut -d: -f2 | sed 's/[\", ]//g')
}
read -r -d '' PE_LINUX_GROUP << LINUX_JSON
{
"classes": {
"profile::pe_env": {},
"profile::repos": {
"offline": "false"
},
"ntp": {}
},
"environment": "production",
"environment_trumps": false,
"name": "Linux Servers2",
"parent": "00000000-0000-4000-8000-000000000000",
"rule": [
"and",
[
"not",
[
"=",
[
"fact",
"clientcert"
],
"$PE_CERTNAME"
]
],
[
"=",
[
"fact",
"kernel"
],
"Linux"
]
],
"variables": {}
}
LINUX_JSON
curl -X POST -H 'Content-Type: application/json' -d "$PE_LINUX_GROUP" $NC_CURL_OPT --insecure https://localhost:4433/classifier-api/v1/groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment