Creating puppet classes and importing the puppet class from a puppet proxy for an environment

Hi,

I am beginner to Foreman API and am attempting to do the following stuff
using the same API but, not able to find proper resources/examples for
posting the JSON request.

  1. Using POST “/api/puppetclasses” API with the following JSON request, 
    

I can create an empty puppet class.

{

"puppetclass": {

"name": "test_class"

}

}

But, how can I provide resource types configuration into that class using
POST JSON request.

e.g.,

class test_class {

file { 'C:\test.txt’:

ensure => file,

content => 'Test Puppet', 

}

}

  1. After I create the puppet class, I want to import the class from a 
    

puppet proxy for an environment using POST
“/api/environments/:environment_id/smart_proxies/:id/import_puppetclasses
<API documentation>”
API with the below mentioned JSON request.

{

"puppetclass": {

&quot;name&quot;: &quot;test_class&quot;

},

"environments":{

  &quot;id&quot;: &quot;1&quot;     # Created environment Id

}

}

Even though the response code is "201” but, I am not able find the
mentioned puppet class is imported from the puppet proxy for the particular
environment.

So, anybody please rectify me or guide me on this.

Regards

Amrit

> Hi,
>
>
>
> I am beginner to Foreman API and am attempting to do the following stuff
> using the same API but, not able to find proper resources/examples for
> posting the JSON request.
>
>
>
> 1. Using POST “/api/puppetclasses” API with the following JSON
> request, I can create an empty puppet class.
>
> {
>
> "puppetclass": {
>
> "name": "test_class"
>
> }
>
> }
>
>
>
> But, how can I provide resource types configuration into that class
> using POST JSON request.

This isn't possible at all with the API, there's no functionality in
Foreman for what you're trying to do.

To deploy a Puppet class you need to put it on the Puppet master
yourself, not using Foreman.

  1. Create manifest files, e.g. test_class/manifests/init.pp
  2. Deploy them to the Puppet master, i.e. under
    /etc/puppet/environments/production/modules (tools like r10k,
    librarian-puppet may automate it)
  3. Import classes/environments in the Foreman UI, or trigger the API etc.

> 2. After I create the puppet class, I want to import the class from
> a puppet proxy for an environment using POST
> “/api/environments/:environment_id/smart_proxies/:id/import_puppetclasses <API documentation>”
> API with the below mentioned JSON request.

This assumes the class is on the smart proxy already. It'll create the
Puppet class in Foreman's database and assign it to environments,
replacing your step (1).

··· On 13/05/16 05:47, Amrit Atmajit wrote:


Dominic Cleal
dominic@cleal.org