Host inheritance of hostgroup values

Is there a way to prevent the host from inheriting a host group value if it
is not set?

I have written a small plugin that sets the environment based on the
hostname. However, if I then select the hostgroup it resets that
environment to blank because the hostgroup doesn't have a value.

I have tried everything via javascript to get around this. I set an
onsubmit function to set the environment (again based on hostname) but this
onsbumit function gets over-ridden (I think) when the hostgroup is
selected.

My solution was to over-ride the Environment select box and disable the
inheritance. That seemed to work.

··· On Saturday, July 9, 2016 at 1:56:13 PM UTC-7, Matthew Ceroni wrote: > > Is there a way to prevent the host from inheriting a host group value if > it is not set? > > I have written a small plugin that sets the environment based on the > hostname. However, if I then select the hostgroup it resets that > environment to blank because the hostgroup doesn't have a value. > > I have tried everything via javascript to get around this. I set an > onsubmit function to set the environment (again based on hostname) but this > onsbumit function gets over-ridden (I think) when the hostgroup is > selected. > > >

Hi,
First I want to make sure what version of foreman do you have and are you
using Katello plugin? Especially do you have the "inherit" button on the
environment field.
If you do - you have two choices: one would be to set the environment field
in the server side ( create a filter method and add it to HostsController
class) you can see an example here
<https://github.com/theforeman/foreman/blob/develop/app/controllers/hosts_controller.rb#L24>
.
Second choice would be to do it on client side - you can mimic the way the
property is marked when it's set by the server: You can add "data-explicit"
attribute to the field.

You can find the JS that manipulates this field here
<https://github.com/theforeman/foreman/blob/develop/app/assets/javascripts/application.js#L573>
.

··· On Saturday, July 9, 2016 at 11:56:13 PM UTC+3, Matthew Ceroni wrote: > > Is there a way to prevent the host from inheriting a host group value if > it is not set? > > I have written a small plugin that sets the environment based on the > hostname. However, if I then select the hostgroup it resets that > environment to blank because the hostgroup doesn't have a value. > > I have tried everything via javascript to get around this. I set an > onsubmit function to set the environment (again based on hostname) but this > onsbumit function gets over-ridden (I think) when the hostgroup is > selected. > > >

I am on 1.11.0

I ended up taking the client side method, as that was the easiest for me to
accomplish.

Thanks

··· On Sunday, July 10, 2016 at 1:44:43 AM UTC-7, ssh...@redhat.com wrote: > > > Hi, > First I want to make sure what version of foreman do you have and are you > using Katello plugin? Especially do you have the "inherit" button on the > environment field. > If you do - you have two choices: one would be to set the environment > field in the server side ( create a filter method and add it to > HostsController class) you can see an example here > > . > Second choice would be to do it on client side - you can mimic the way the > property is marked when it's set by the server: You can add "data-explicit" > attribute to the field. > > You can find the JS that manipulates this field here > > . > > > On Saturday, July 9, 2016 at 11:56:13 PM UTC+3, Matthew Ceroni wrote: >> >> Is there a way to prevent the host from inheriting a host group value if >> it is not set? >> >> I have written a small plugin that sets the environment based on the >> hostname. However, if I then select the hostgroup it resets that >> environment to blank because the hostgroup doesn't have a value. >> >> I have tried everything via javascript to get around this. I set an >> onsubmit function to set the environment (again based on hostname) but this >> onsbumit function gets over-ridden (I think) when the hostgroup is >> selected. >> >> >>