Deactivating nodes in Puppet using PowerShell

10 views
Skip to first unread message

Ryan Murphy

unread,
Apr 18, 2018, 1:19:34 PM4/18/18
to Puppet Users
Ok folks, since I got help last time, thought I'd try again.  This time I'm trying to deactivate nodes instead of signing their certs.

Here is the code, the first two invoke-restmethods work as expected. But when I try to call the command to Deactivate the node it throws a Schema error.

$ErrorActionPreference = 'continue'

[System.net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

$console_server = 'puppetmater.domain'

$node = "node.domain"

$action = @{desired_state='revoked'}
$json = $action | ConvertTo-Json


$url = "https://${console_server}:8140/puppet-ca/v1/certificate_status/${node}"

echo $url


$results = Invoke-RestMethod -Uri "$url" -body $json -method PUT -Certificate (Get-PfxCertificate -FilePath \\server\puppet-certs\Non-Production\certname)

$url = "https://${console_server}:8140/puppet-ca/v1/certificate_status/${node}"

$response = Invoke-RestMethod -Uri "$url" -method DELETE -Certificate (Get-PfxCertificate -FilePath \\server\puppet-certs\Non-Production\certname)


echo $response


$deactivateAction = @{command="deactivate node"
                        version='3' 
                        payload=@{
                            certname="$node"
                            }
                         }
$json2 = $deactivateAction | ConvertTo-Json

$commandURL = "https://${console_server}:8081/pdb/cmd/v1"

echo $json2


$response = Invoke-RestMethod -Uri $commandURL -Method Post  -ContentType 'application/json' -Body $json2 -Certificate (Get-PfxCertificate -FilePath \\server\puppet-certs\Non-Production\certname.pfx)

echo $response


Ryan Murphy

unread,
Apr 18, 2018, 4:23:08 PM4/18/18
to Puppet Users
I figured it out.  Found the correct version of the documentation that showed the proper URL.  Although I think it could be written a little better.  But oh well
Reply all
Reply to author
Forward
0 new messages