Persistently change server attributes in the Rails Console

I’m experimenting with adjusting server attributes from the Rails console and I’m running into issues. Hopefully someone can shed some light on this.

Being able to do this has a lot of implications, but primarily, it would be neat to know how to turn the UI role back on in a standalone appliance that had it turned off. Long ago, there was a way to do this through config/settings.yml but that file hasn’t seemed to actually do anything for a while. So I tried a couple of other things. As an example let’s say I’m trying to enable the websocket role in an appliance that has it turned off.

I can see what roles are enabled by executing:


from the rails console. This gives me something like:

irb(main):001:0> MiqServer.my_server.role
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
=> "automate,database_operations,database_owner,event,reporting,scheduler,user_interface,web_services"

I can make the websocket role show up in the rails console by executing:


or something like:

MiqServer.my_server.update_attributes(:role => "automate,database_operations,database_owner,event,reporting,scheduler,user_interface,web_services,websocket")

That change persists through rails console sessions, but does not survive an evmserverd restart. It also never shows up in the UI in the configuration menu, so for all intents and purposes I assume it’s not taking effect. Since that didn’t work I thought maybe the “save” method might work, so I tried this on both:

and even:!

for good measure. But neither work. Nothing survives a process restart and nothing ever impacts the settings in the UI.

Anyone have any ideas?

I think you’re looking for Settings. Specifically, during MiqServer.atStartup (link), you can see that the role is read from ::Settings.server.role.

1 Like

@fryguy I believe that MiqServer.my_server.role = ... should work in persisting a change to your roles but it’s not updating ::Settings (settings_changes), so on reboot, as @himdel shows, it gets reset to the defaults on startup of the server.

It feels like role= should be doing something like this as the end:!(self, :server => {:role => val})


1 Like

I’ve had success with the following strategy:

server = MiqServer.my_server
vmdb = server.get_config
vmdb.config[:server][:role] = 'full,list,of,roles'
1 Like

@jrafanie As @deric.crago stated, the “right” way to apply settings to an MiqServer is via #set_config. Part of the reason is that this interface is non-local-server aware, so you can apply settings to any server.

You can also give a sparse hash to #set_config, so it could even be done in one line with

MiqServer.my_server.set_config(:server => {:role => "full,set,of,roles"})

There are also helper methods for getting the existing role set, such as MiqServer.my_server.assigned_role_names

So, @jrafanie, if #role= previously saved the value, then yes, I believe the implementation should be changed to go through set_config.

1 Like

I should have noted previously, but the configuration value in the settings is really meant for telling an appliance what the “default” set of roles are at boot. So, even if you change it via set_config directly, it won’t take affect until you restart the process. I believe #role= currently does the right thing in that it updates the server_roles and assigned_server_roles tables, so that needs to stay, but it would be more accurate if the Settings were updated via #set_config as well.

I have long disliked this value being in the Settings, so we may want to remove it altogether at some point, however at present it is just wrong and we should fix it.

1 Like

Thanks for all the help guys, I wrote up a post on this if you’re interested.

Thanks again.

1 Like