Problem:
I’m building Foreman 1.15.7 from source (and have tried 1.17 as well with the same results). Ruby 2.3.7 backed by PostgreSQL. I saw in the release notes that there is now a default Host Owner, but this seems to be failing whenever I run RAILS_ENV=production bundle exec rake db:migrate
The release notes state this can be nil by default. “A new setting “Host Owner” (under Administer > Settings) allows to set an default owner for newly provisioned hosts. The default owner can be a user or an user group, and the feature can be disabled if it is not needed.”
The validate code (in app/models/setting.rb) seems to bomb out if it’s nil. So how does this get populated or disabled per the release notes above?
def validate_host_owner
owner_type_and_id = self.value
return if owner_type_and_id.blank?
owner = OwnerClassifier.new(owner_type_and_id).user_or_usergroup
errors.add(:value, _("Host owner is invalid")) if owner.nil?
end
Expected outcome:
Seed the DB
Foreman and Proxy versions:
1.15.7
Foreman and Proxy plugin versions:
Other relevant data:
Called from /opt/houston/tools/ruby-2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Value Host owner is invalid
/opt/houston/services/foreman-1.15.7/app/models/setting.rb:215:in `create!'
/opt/houston/services/foreman-1.15.7/app/models/setting/provisioning.rb:52:in `block (2 levels) in load_defaults'
/opt/houston/services/foreman-1.15.7/app/models/setting/provisioning.rb:52:in `each'
/opt/houston/services/foreman-1.15.7/app/models/setting/provisioning.rb:52:in `block in load_defaults'
/opt/houston/services/foreman-1.15.7/app/models/setting/provisioning.rb:51:in `load_defaults'
/opt/houston/services/foreman-1.15.7/config/initializers/foreman.rb:26:in `each'
/opt/houston/services/foreman-1.15.7/config/initializers/foreman.rb:26:in `<top (required)>'
/opt/houston/services/foreman-1.15.7/config/environment.rb:5:in `<top (required)>'
/opt/houston/tools/ruby/bin/bundle:22:in `load'
/opt/houston/tools/ruby/bin/bundle:22:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Do you see this for every host you try to create?
The 2nd line return if owner_type_and_id.blank?
ensures that if you haven’t chosen the owner type (User or User group) it should not fail. I’m able to create hosts without owner, when do you see this error?
The available values for the setting are dynamic, depending on the users/user groups available.
This is during building / installing from source. Haven’t gotten to the point where Foreman is even running yet. For additional context, this is a CentOS 7 system in a docker container, and I’m running as root (but have also tried as a non-root user with same results)
Doing the following (which works for 1.14.x and below):
- git cloning 1.15.7
- populating settings.yaml
- populating database.yml
- bundle install / npm install
- RAILS_ENV=production bundle exec rake webpack:compile
- RAILS_ENV=production bundle exec rake db:migrate assets:precompile locale:pack
- RAILS_ENV=production bundle exec rake db:seed assets:precompile locale:pack
Hello,
Did you set the owner in settings.yaml? the second line of that method should simply skip the validation in case the setting is nil or empty string. But in your case, it seems it’s not. So perhaps uploading your settings.yml could help understand what’s going on.
–
Marek
Yeah absolutely - happy to share, sorry for not getting ahead of that earlier. Appreciate all of the suggestions! Is there a setting for this in settings.yaml? I didn’t see anything in the example – but also fairly sure I did try setting a :host_owner: for kicks at one point
:domain: ‘domainname.xxxxx’ # Has real data here which matches fqdn of box, hostname -f, etc.
:fqdn: ‘hostname.domainname.xxxxx’ # per above
:unattended: true
:login: true
:require_ssl: false
:locations_enabled: false
:organizations_enabled: false
:puppetconfdir: $PUPPET_HOME/configServer
:puppetvardir: $PUPPET_HOME/configServer/var
:puppetgem: true
:mark_translated: false
Also, for the curious, I’m going this route because I don’t have root and things like RPM are a no go in my environment sadly
Another note is that I don’t seem to have a host_owner column in my DB settings table. Doesn’t seem to get created?
You can add any setting in settings.yaml, which makes it “hardcoded” and can’t be changed from UI later. But your settings does not list any host owner, so it’s not the cause.
There’s no host_owner column, we use owner_id
for the foreign key and owner_type
to determine, whether the owner is user or user group.
Strange thing is that this is how we install Foreman in our jenkins when we run tests and we haven’t seen this issue, or at least I don’t recall. Could you try build newer version of Foreman? The recent stable is 1.17.1.
Yeah this is the case with 1.17.1 as well. That’s where I started and began backtracking to see where the failure was introduced. I’m currently building and using a 1.14.x just fine and have been using this method for a long time. As per the release notes in 1.15.x:
“A new setting “Host Owner” (under Administer > Settings) allows to set an default owner for newly provisioned hosts. The default owner can be a user or an user group, and the feature can be disabled if it is not needed.”
Guessing it’s related to that. I bet it’s something environmental though - something related to my docker container or configuration. I’ll try spinning up a clean VM instead of container and build off that to compare
Yup - sure enough, building in a VM versus my docker container was successful. Something environmental. Will dig into things deeper 
1 Like