Ask Your Question
0

Use agent environment in ENC

asked 2018-02-26 20:10:07 -0600

Hypnoz gravatar image

updated 2018-03-04 03:34:29 -0600

I would like to access the "environment" the client node is requesting from inside my ENC script.

I see tickets like this where it seems to be resolved:

But I just can't figure out what variable will give me this info. Assuming my ENC is a simple Ruby script that just creates a role based on hostname, an example would be especially helpful.

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-03-06 16:53:37 -0600

Hypnoz gravatar image

updated 2018-03-06 17:25:07 -0600

I was able to resolve this by looking into puppetdb in the ENC script for "agent_specified_environment"

curl -X GET http://puppetdb001.example.com:8080/pdb/query/v4/facts --data-urlencode 'query=["and", ["=", "name", "agent_specified_environment"], ["=", ["fact", "clientcert"], "puppettest001.example.com"]]'

Inside a ruby script, it would be like this:

require 'net/http'
require 'uri'
require 'json'uri = URI.parse("http://puppetdb001.example.com:8080/pdb/query/v4/facts")
request = Net::HTTP::Get.new(uri)
request.body = "query=[\"and\",
  [\"=\", \"name\", \"agent_specified_environment\"],
  [\"=\", [\"fact\", \"clientcert\"], \"puppettest001.example.com\"]
  ]"

req_options = {
  #  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

response_env = JSON.parse(response.body)[0]["value"]
print response_env

I found this value is created with the correct environment, and is available before the ENC runs so it's true.

edit flag offensive delete link more

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

Stats

Asked: 2018-02-26 20:10:07 -0600

Seen: 333 times

Last updated: Mar 06