Project

General

Profile

Actions

Bug #14541

closed

foreman-rake must preserve environment variables

Added by Jérôme Vizcaino almost 8 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Rake tasks
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Calling foreman-rake db:seed fills the database with default entries.
Of theses seeds, 04-admin.rb takes care of adding the default admin account.
This can be configured using SEED_ADMIN_* environment variables but calling foreman-rake with id != foreman fails.

Looking at foreman-rake, the su call misses the -p flag, so environment is dropped when changing user.

Actions #1

Updated by Dominic Cleal almost 8 years ago

  • Category set to Rake tasks
Actions #2

Updated by The Foreman Bot almost 8 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3533 added
Actions #3

Updated by Stijn Tintel almost 8 years ago

Adding -p to the su call is unfortunately not an option:

root@foreman:~# /usr/sbin/foreman-rake db:seed
-su: /root/.bash_profile: Permission denied
rake aborted!
Errno::EACCES: Permission denied - /root/.facter/facts.d
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `open'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `entries'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `entries'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:55:in `load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `block in load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `each'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:154:in `load_external_facts'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:110:in `load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:84:in `fact'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:140:in `value'
/usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter.rb:112:in `block (2 levels) in singleton class'
/usr/share/foreman/app/models/setting/general.rb:7:in `load_defaults'
/usr/share/foreman/config/initializers/foreman.rb:21:in `each'
/usr/share/foreman/config/initializers/foreman.rb:21:in `<top (required)>'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `block in load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `load'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:648:in `block in load_config_initializer'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/notifications.rb:161:in `instrument'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:647:in `load_config_initializer'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:611:in `each'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:611:in `block in <class:Engine>'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:30:in `instance_exec'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:30:in `run'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:44:in `each'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:44:in `tsort_each_child'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:54:in `run_initializers'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:300:in `initialize!'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/railtie.rb:194:in `public_send'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/railtie.rb:194:in `method_missing'
/usr/share/foreman/config/environment.rb:5:in `<top (required)>'
/usr/share/foreman/vendor/ruby/2.0.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/usr/share/foreman/vendor/ruby/2.0.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:247:in `block in require'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:247:in `require'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:276:in `require_environment!'
/usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:405:in `block in run_tasks_blocks'
/usr/share/foreman/vendor/ruby/2.0.0/gems/activerecord-4.1.14.2/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
/usr/bin/rake2.0:37:in `<main>'
Tasks: TOP => db:abort_if_pending_migrations => environment
(See full trace by running task with --trace)

Actions #4

Updated by Dominic Cleal almost 8 years ago

  • Status changed from Ready For Testing to New
  • Pull request deleted (https://github.com/theforeman/foreman/pull/3533)

HOME might be carried through with -p?

Actions #5

Updated by Stijn Tintel almost 8 years ago

This is just a warning and can be ignored:

-su: /root/.bash_profile: Permission denied

But the problem seems to be in the facter gem, in /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/config.rb:

  def self.external_facts_dirs
    if Facter::Util::Root.root?
      windows_dir = windows_data_dir
      if windows_dir.nil? then
        ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
      else
        [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
      end
    else
      [File.expand_path(File.join("~", ".facter", "facts.d"))]
    end
  end

So with the -p option, the environment contains HOME=/root, which is causing the above problem.

Actions #6

Updated by The Foreman Bot almost 8 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3534 added
Actions #7

Updated by Anonymous almost 8 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #8

Updated by Dominic Cleal almost 8 years ago

  • translation missing: en.field_release set to 136
Actions

Also available in: Atom PDF