Helping finding in depth manuals for sc-param update and proxy import

Problem:

We I run a proxy import of classes, the cast class datatype of Boolean is ignored and the sc-param datatype is a string.
This causes an issue with adding a value, as instead of true or false , I get [“true”] as the host override.

Expected outcome:
For the proxy import to respect datatype cast values in the top of classes

for example
class my (
Boolean $key = false
) { stuff}

Foreman and Proxy versions:
1.15/puppet3.8.7. This works fine although the datatype as string issue still exists.
it sends true as the value not extras. true
which allows a puppet run to work.
1.16/puppet5. This fails and the data import goes wrong due to [“true”] being posted.
post setting this a puppet run fails with a datatype error on class

Other relevant data:

Am a little confused as to where the extra [""] is coming from and could do with a very deep dive on a good advance manual to find the answer

Summary

  1. proxy import doesnt respect datatype set in class everything is a string. Is this correct? Mainly seeing issues around boolean, which I know changed post puppet3, this is reason for the Boolean casting in the first place.

  2. finding a really good manual to read so I can work out a workaround.
    at the moment

hammer sc-param update --id 1721 --puppet-class-id 280 --parameter-type boolean --override true
this will if the puppet value to the field isnt bool! which as this just shows the string showing the inherit string not the value of the look up. This is something that is rather big short coming. it should follow the logic and return the result not just print the path to the value.

Is this issue resolved in 1.17 and is that stable enough to try?

example from CLI.

[root@p5foreman vagrant]# hammer sc-param update --id 1721 --puppet-class-id 280 --parameter-type string --override true --default-value false
Parameter updated
[root@p5foreman vagrant]# hammer sc-param update --id 1721 --puppet-class-id 280 --parameter-type boolean --override true
Could not update the parameter:
Validation failed: Default value is invalid
[root@p5foreman vagrant]# hammer sc-param info --id 1721
Id: 1721
Parameter: client
Default Value: [“false”]

Once the default value gets this [" stuff it is bust! and wouldnt go back.

how do you blank the default off so it can be set again. it is most annoying , can sc-param be deleted? i couldnt see an remove option

strbool gets around the [" extras on raw input. however the fact remind proxy import is ignoring the cast Boolean. this should be fixed! if possible. look up cast before $ then act on this and set sc-param based on it.

in P4 and above strings are different when it comes to true/false,p3 u get true p4_ u ge, t [“true”] for a string value. if foreman continues to cast imports as strings , code breaks and we need workarounds like str2bool embedded into the class.

Why? coding a cast because u can trust your input values. fair enough!
str2bool wins! $my_var = str2bool($var)

We should be providing the correct data types through YAML so you don’t need to convert it inside your classes.

I wonder if you can replicate the issue when using the Foreman UI which would mean it’s an API issue.

I’d like to know the answer to @ekohl’s questions but I can already answer about the delete: sc-param can not be deleted. They are only deleted if they are removed from the puppet class and it’s imported again.

The first command example that used the --default-value flag seems correct and looks like a workaround (changing the default value when changing the type). Is there an issue with it or only when not changing the default-value?

I have been testing further on this and can confirm that the data-flow we use to get the data into foreman is as followings and found issues with both steps

We use hammer to import classes via proxy-import: issue this reads Boolean varibles as string

We have a JSON doc not YAML, but that shouldnt matter. that deals hostgroups/roles , plus any class overrides we have. This usest the using hammer-cli. up to foreman1.17 this has issues around writing said miss configured Bool strings as a one element array.
I will be testing the new hammer-cli with the new add-mater option this week, will post my results. As if this works can this be put into 17.x?

Using the GUI to update the values to true or false works! and so far is the only workaround I can confirm.

However another issue exists around Boolean. Try setting the default to true in the puppet class and then over ride it, via hammer this fails. Although this might be related to the sending an Array[“false”] not a Bool true or string “true”

chears! wondered why I couldnt find one

There are two problems here:
1/ the param types are not recognized properly during import on Puppet >= 4. I’ve found some related open issues and it needs some investigation to be fixed
2/ the API params were improperly documented and Hammer reads the type of the value as an array. This was fixed in API with [1] and workarounded in hammer with [2]. The fix in Hammer is in version 0.13.0 that should land in Foreman 1.18. I’m going to cherry-pick the hammer fix to 0.12.1 that could make it to Foreman 1.17.2.

[1] https://github.com/theforeman/foreman/commit/cb591e34f4e1f462b826a5f391bed20ceb192da3
[2] https://github.com/theforeman/hammer-cli-foreman/commit/bfe13ff4c17a90a23c13df6a875917c2d827db64

1 Like