Add class to an host through API

Hello,

I am trying to find a system that will allow me to interact with puppet
from an application, interaction is quite simple, I have to be able to add
some classes to an host. My first thought was to use foreman as an ENC and
through the foreman REST API add classes to my host. But after re-reading
the API documentation, I'm not sure anymore it's possible, is it ?

Julien

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the host belongs to. Its important to note that while you can't simple add/remove classes you have to re-post all the classes the host needs to belong to. So to remove "C" in set A, B, C, D you would need to POST classes=A,B,D.

Does this help?

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

··· On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,

I am trying to find a system that will allow me to interact with puppet from an application, interaction is quite simple, I have to be able to add some classes to an host. My first thought was to use foreman as an ENC and through the foreman REST API add classes to my host. But after re-reading the API documentation, I’m not sure anymore it’s possible, is it ?

Julien

> Have you tried RemoteAdmin? (http://www.remoteadmin.co)
>
>
> To add classes to the host just use a http post to change the classes the
> host belongs to. Its important to note that while you can't simple
> add/remove classes you have to re-post all the classes the host needs to
> belong to. So to remove "C" in set A, B, C, D you would need to POST
> classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

··· On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman wrote: > Does this help? > > Corey Osman > corey@logicminds.biz > Green I.T and Datacenter Automation Specialist > > > On Nov 28, 2011, at 8:41 AM, Julien Garet wrote: > > Hello, > I am trying to find a system that will allow me to interact with puppet from > an application, interaction is quite simple, I have to be able to add some > classes to an host. My first thought was to use foreman as an ENC and > through the foreman REST API add classes to my host. But after re-reading > the API documentation, I'm not sure anymore it's possible, is it ? > Julien >

> Hello,
> I am trying to find a system that will allow me to interact with puppet from
> an application, interaction is quite simple, I have to be able to add some
> classes to an host. My first thought was to use foreman as an ENC and
> through the foreman REST API add classes to my host. But after re-reading
> the API documentation, I'm not sure anymore it's possible, is it ?

It is possible, its most likely an documentation 'feature' :slight_smile:

in general, the best way to find out, is to look at your logs and see
how the request looks like.

Ohad

··· On Mon, Nov 28, 2011 at 6:41 PM, Julien Garet wrote: > Julien

Your probably right. I might have only tested with the POST statement instead of PUT.

Corey

··· On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the
host belongs to. Its important to note that while you can’t simple
add/remove classes you have to re-post all the classes the host needs to
belong to. So to remove “C” in set A, B, C, D you would need to POST
classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman
corey@logicminds.biz
Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,
I am trying to find a system that will allow me to interact with puppet from
an application, interaction is quite simple, I have to be able to add some
classes to an host. My first thought was to use foreman as an ENC and
through the foreman REST API add classes to my host. But after re-reading
the API documentation, I’m not sure anymore it’s possible, is it ?
Julien

Thanks for your answers, so it might be possible, but when I look at the
doc for the API (API - Foreman), I can't
find the correct API call to update puppet classes.

/puppetclasses only refers to classes known by foreman
/hosts/FQDN/puppetclasses is only a GET call
/hosts/FQDN is a PUT call but does not contain

Looking at the logs, I've something like
/puppetclasses/myclass/assign?type=host but I can't figure the data I
should pass to it.

Julien

··· 2011/11/28 Corey Osman

Your probably right. I might have only tested with the POST statement
instead of PUT.

Corey

On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the

host belongs to. Its important to note that while you can’t simple

add/remove classes you have to re-post all the classes the host needs to

belong to. So to remove “C” in set A, B, C, D you would need to POST

classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman

corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,

I am trying to find a system that will allow me to interact with puppet
from

an application, interaction is quite simple, I have to be able to add some

classes to an host. My first thought was to use foreman as an ENC and

through the foreman REST API add classes to my host. But after re-reading

the API documentation, I’m not sure anymore it’s possible, is it ?

Julien

Julien,

Here is how I do it in Remote Admin.

Since I am actually just updating my internal host model I have a to_json function that creates the JSON text below. So this will update the host with all the puppetclass_ids (not just the deltas).
In my case it makes sense this way because I have a batch update that equates to remove class x,y and add class z all in one http call. The actually foreman WEB-UI method may be different but since I am on a mobile device
I want to keep http calls to a minimum.

Method: PUT
URL: https://foreman/hosts/FQDN

JSON Text:
{"environment_id":1,"hostgroup_id":5,"name":"system1.logicminds.corp","id":47,"_method":"put","host":{"puppetclass_ids":[11,37,8,45]}}

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

··· On Nov 28, 2011, at 11:57 PM, Julien Garet wrote:

Thanks for your answers, so it might be possible, but when I look at the doc for the API (API - Foreman), I can’t find the correct API call to update puppet classes.

/puppetclasses only refers to classes known by foreman
/hosts/FQDN/puppetclasses is only a GET call
/hosts/FQDN is a PUT call but does not contain

Looking at the logs, I’ve something like /puppetclasses/myclass/assign?type=host but I can’t figure the data I should pass to it.

Julien

2011/11/28 Corey Osman corey@logicminds.biz

Your probably right. I might have only tested with the POST statement instead of PUT.

Corey

On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the
host belongs to. Its important to note that while you can’t simple
add/remove classes you have to re-post all the classes the host needs to
belong to. So to remove “C” in set A, B, C, D you would need to POST
classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman
corey@logicminds.biz
Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,
I am trying to find a system that will allow me to interact with puppet from
an application, interaction is quite simple, I have to be able to add some
classes to an host. My first thought was to use foreman as an ENC and
through the foreman REST API add classes to my host. But after re-reading
the API documentation, I’m not sure anymore it’s possible, is it ?
Julien

Thanks again for your answer, is it possible to had parameters to my classes with this method ?

Julien Garet

··· Le 29 nov. 2011 à 19:48, Corey Osman a écrit :

Julien,

Here is how I do it in Remote Admin.

Since I am actually just updating my internal host model I have a to_json function that creates the JSON text below. So this will update the host with all the puppetclass_ids (not just the deltas).
In my case it makes sense this way because I have a batch update that equates to remove class x,y and add class z all in one http call. The actually foreman WEB-UI method may be different but since I am on a mobile device
I want to keep http calls to a minimum.

Method: PUT
URL: https://foreman/hosts/FQDN

JSON Text:
{“environment_id”:1,“hostgroup_id”:5,“name”:“system1.logicminds.corp”,“id”:47,"_method":“put”,“host”:{“puppetclass_ids”:[11,37,8,45]}}

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 11:57 PM, Julien Garet wrote:

Thanks for your answers, so it might be possible, but when I look at the doc for the API (API - Foreman), I can’t find the correct API call to update puppet classes.

/puppetclasses only refers to classes known by foreman
/hosts/FQDN/puppetclasses is only a GET call
/hosts/FQDN is a PUT call but does not contain

Looking at the logs, I’ve something like /puppetclasses/myclass/assign?type=host but I can’t figure the data I should pass to it.

Julien

2011/11/28 Corey Osman corey@logicminds.biz

Your probably right. I might have only tested with the POST statement instead of PUT.

Corey

On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the
host belongs to. Its important to note that while you can’t simple
add/remove classes you have to re-post all the classes the host needs to
belong to. So to remove “C” in set A, B, C, D you would need to POST
classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman
corey@logicminds.biz
Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,
I am trying to find a system that will allow me to interact with puppet from
an application, interaction is quite simple, I have to be able to add some
classes to an host. My first thought was to use foreman as an ENC and
through the foreman REST API add classes to my host. But after re-reading
the API documentation, I’m not sure anymore it’s possible, is it ?
Julien

AFAIK, You cannot add parameters to the classes from this api call. However you can add parameters to the host that the classes can reference. Example

  1. New host parameter
  2. parameter: donttouchme = true

In the puppet class you would do something like this:

if $donttouchme != "true"

   # touch me

else
# I said don't touch me

end

However, I think what you want is a method to pass default class variables from parameters. Maybe Ohad assist on this specific query.

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

··· On Nov 29, 2011, at 10:54 AM, Julien Garet wrote:

Thanks again for your answer, is it possible to had parameters to my classes with this method ?

Julien Garet

Le 29 nov. 2011 à 19:48, Corey Osman corey@logicminds.biz a écrit :

Julien,

Here is how I do it in Remote Admin.

Since I am actually just updating my internal host model I have a to_json function that creates the JSON text below. So this will update the host with all the puppetclass_ids (not just the deltas).
In my case it makes sense this way because I have a batch update that equates to remove class x,y and add class z all in one http call. The actually foreman WEB-UI method may be different but since I am on a mobile device
I want to keep http calls to a minimum.

Method: PUT
URL: https://foreman/hosts/FQDN

JSON Text:
{“environment_id”:1,“hostgroup_id”:5,“name”:“system1.logicminds.corp”,“id”:47,"_method":“put”,“host”:{“puppetclass_ids”:[11,37,8,45]}}

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 11:57 PM, Julien Garet wrote:

Thanks for your answers, so it might be possible, but when I look at the doc for the API (API - Foreman), I can’t find the correct API call to update puppet classes.

/puppetclasses only refers to classes known by foreman
/hosts/FQDN/puppetclasses is only a GET call
/hosts/FQDN is a PUT call but does not contain

Looking at the logs, I’ve something like /puppetclasses/myclass/assign?type=host but I can’t figure the data I should pass to it.

Julien

2011/11/28 Corey Osman corey@logicminds.biz

Your probably right. I might have only tested with the POST statement instead of PUT.

Corey

On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the
host belongs to. Its important to note that while you can’t simple
add/remove classes you have to re-post all the classes the host needs to
belong to. So to remove “C” in set A, B, C, D you would need to POST
classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman
corey@logicminds.biz
Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,
I am trying to find a system that will allow me to interact with puppet from
an application, interaction is quite simple, I have to be able to add some
classes to an host. My first thought was to use foreman as an ENC and
through the foreman REST API add classes to my host. But after re-reading
the API documentation, I’m not sure anymore it’s possible, is it ?
Julien

Yes, I am planning to use parametrized classes from puppet. I think host
parameters can do the job, but If I do as you tell, I need to change my
classes to be "foreman aware", and I don't think it's the best way to do
things, because then my recipes could only be used by people using foreman.
It's a limitation and not in the way one should develop recipes for puppet
(being platform dependent).

··· 2011/11/29 Corey Osman

AFAIK, You cannot add parameters to the classes from this api call.
However you can add parameters to the host that the classes can reference.
Example

  1. New host parameter
  2. parameter: donttouchme = true

In the puppet class you would do something like this:

if $donttouchme != “true”
# touch me

else

I said don’t touch me

end

However, I think what you want is a method to pass default class
variables from parameters. Maybe Ohad assist on this specific query.

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 29, 2011, at 10:54 AM, Julien Garet wrote:

Thanks again for your answer, is it possible to had parameters to my
classes with this method ?

Julien Garet

Le 29 nov. 2011 à 19:48, Corey Osman corey@logicminds.biz a écrit :

Julien,

Here is how I do it in Remote Admin.

Since I am actually just updating my internal host model I have a to_json
function that creates the JSON text below. So this will update the host
with all the puppetclass_ids (not just the deltas).
In my case it makes sense this way because I have a batch update that
equates to remove class x,y and add class z all in one http call. The
actually foreman WEB-UI method may be different but since I am on a mobile
device
I want to keep http calls to a minimum.

Method: PUT
URL: https://foreman/hosts/FQDN

JSON Text:

{“environment_id”:1,“hostgroup_id”:5,“name”:“system1.logicminds.corp”,“id”:47,"_method":“put”,“host”:{“puppetclass_ids”:[11,37,8,45]}}

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 11:57 PM, Julien Garet wrote:

Thanks for your answers, so it might be possible, but when I look at the
doc for the API (API - Foreman), I
can’t find the correct API call to update puppet classes.

/puppetclasses only refers to classes known by foreman
/hosts/FQDN/puppetclasses is only a GET call
/hosts/FQDN is a PUT call but does not contain

Looking at the logs, I’ve something like
/puppetclasses/myclass/assign?type=host but I can’t figure the data I
should pass to it.

Julien

2011/11/28 Corey Osman corey@logicminds.biz

Your probably right. I might have only tested with the POST statement
instead of PUT.

Corey

On Nov 28, 2011, at 10:35 AM, Ohad Levy wrote:

On Mon, Nov 28, 2011 at 7:29 PM, Corey Osman corey@logicminds.biz >> wrote:

Have you tried RemoteAdmin? (http://www.remoteadmin.co)

To add classes to the host just use a http post to change the classes the

host belongs to. Its important to note that while you can’t simple

add/remove classes you have to re-post all the classes the host needs to

belong to. So to remove “C” in set A, B, C, D you would need to POST

classes=A,B,D.

Are you sure about that? I think that a PUT with what was added /
removed would not require you to send the whole thing again.
.
Ohad

Does this help?

Corey Osman

corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

On Nov 28, 2011, at 8:41 AM, Julien Garet wrote:

Hello,

I am trying to find a system that will allow me to interact with puppet
from

an application, interaction is quite simple, I have to be able to add some

classes to an host. My first thought was to use foreman as an ENC and

through the foreman REST API add classes to my host. But after re-reading

the API documentation, I’m not sure anymore it’s possible, is it ?

Julien