Support #9387

How to override smart parameters in JSON call

Added by Brian Lee almost 8 years ago. Updated almost 6 years ago.

Target version:
Fixed in Releases:
Found in Releases:


I am trying to figure out how to override a parameter in a puppet class during the create host API call. I can not seem to find any documentation on that.


#1 Updated by Brian Lee almost 8 years ago

What does this do in the API call: host[host_parameters_attributes]

Is that where I would pass in host parameters like in the UI?

#2 Updated by Dominic Cleal almost 8 years ago

You can, but it's really only there for the convenience of the UI. It's quite possible we don't accept it in future versions through the API.

The API isn't designed to handle nested resources during creation right now, it really expects multiple calls to set everything up. (Note we use the phrase "nested" in a few different ways.. I mean one JSON hash with multiple objects.)

#3 Updated by Brian Lee almost 8 years ago

I know we talked briefly the other day. How would to use the API to create a host with a puppet class added to it and host overrides for it?

#4 Updated by Dominic Cleal almost 8 years ago

I think something like (pseudo-code):

POST /api/v2/hosts

POST /api/v2/puppetclasses/apache/smart_class_parameters/service_ensure/override_values

The latter query should add a matcher to the smart class parameter, as if you'd navigated via Configure > Puppet classes > apache > Smart class params > Add matcher.

The "_name(s)" attributes are automatic convenience methods, saves using IDs.

#5 Updated by Brian Lee almost 8 years ago

My concern about that is the first call is going to install your puppet module with the default values that you provide when the host is being built. Some of mine require the parameters to be in place when puppet runs the first time (other scripts are being run).

Could I do this type of workflow: build host, add puppet classes to host, update parameters, run puppet

If so, what would the json pseudo-code be for adding classes to a host and running puppet (assuming I dont want to wait for the timed run).

#6 Updated by Dominic Cleal almost 8 years ago

The host build should be happening asynchronously though. It's unlikely to be running Puppet by the time you place the second call, though I accept there's no guarantee.

As to your query:

POST /api/v2/hosts

POST /api/v2/puppetclasses/apache/smart_class_parameters/service_ensure/override_values

PUT /api/v2/hosts/

PUT /api/v2/hosts/

(The last assumes you have Puppet runs via Foreman set up with a smart proxy configured for it.)

#7 Updated by Brian Lee almost 8 years ago

When I use postman to create a host with postman or with curl, the command it tied up until the host is built. From what I can that includes puppet running. So breaking it up like you showed me might be the better way to do it.

#8 Updated by Anonymous over 6 years ago

Brian, what's the status here?

#9 Updated by Anonymous almost 6 years ago

  • Status changed from New to Resolved

no reaction, closing.

Also available in: Atom PDF