Ask Your Question

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.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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 --data-urlencode 'query=["and", ["=", "name", "agent_specified_environment"], ["=", ["fact", "clientcert"], ""]]'

Inside a ruby script, it would be like this:

require 'net/http'
require 'uri'
require 'json'uri = URI.parse("")
request =
request.body = "query=[\"and\",
  [\"=\", \"name\", \"agent_specified_environment\"],
  [\"=\", [\"fact\", \"clientcert\"], \"\"]

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

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

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


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

Seen: 336 times

Last updated: Mar 06