Migrating to a new host

Problem:
After migrating to a new host the installer does not read my ‘old’ config

Expected outcome:
Should read the old config

Foreman and Proxy versions:
1.21

Foreman and Proxy plugin versions:

Distribution and version:
CentOS 7.7

Other relevant data:
I know the OS Version AND the foreman version is old.
But I try to migrate from Ubuntu 16.04 to CentOS and I do not want
to change too many things at once.

I dumped and restored the psql
The web interface looks fine already (all the host are visible,…) and
the LDAP authentication is working as well

I copied all files in /etc/foreman to the new server.
But if I run ‘foreman-installer -i’ all settings are on default.
What I have to do that the installer uses/read the config from the machine?

You will need to copy the answers.yaml file that iirc lives in /etc/foreman-installer

Thank you for your hint!
The file:
/etc/foreman-installer/scenarios.d/foreman-answers.yaml
did the trick :+1:

But now this error occurs:
'/usr/bin/initdb --encoding '' --pgdata '/var/lib/pgsql/data'' returned 1 instead of one of [0]

If I check the command manually I get:
initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.

However I do not want that the installer to initializes a new database because
it is already there and filled with data.
Why does the installer does not recognize the data base?

Changing from Ubuntu to CentOS can cause a lot of paths to change because the packaging is different in various places. That can cause a lot of issues. Normally I wouldn’t recommend manually changing answer files, but in this highly unusual thing I’d recommend to go over it and see which are values you’ve changed. If you didn’t, the delete the line. Since it’s a fresh server, that should still be rather safe.

Note that the installer also has a --noop flag which will show you what it would change.

In the future, it’s also helpful to get the log from /var/log/foreman-installer.

The reason for “this highly unusual thing” is the problem regarding Ubuntu described here:

If ‘your’ distribution of choice is RedHat based so be it :slight_smile:

I changed only the host name so far.
These are the values set for the database:

*db_manage: true
*db_type: postgresql
*db_adapter:
*db_host:
*db_port:
*db_database:
*db_username: foreman
*db_password: xxx
*db_sslmode:
*db_root_cert:
*db_pool: 5
*db_manage_rake: true

Maybe my postgres installation is the real problem.
I installed it from scratch. (It is not the version shipped with CentOS!)

The standard (postgres) path is: /var/lib/pgsql/11/data
But the foreman-installer is looking for this path: /var/lib/pgsql/data
So I created a sym link from /var/lib/pgsql/11/data to /var/lib/pgsql/data
But after the installer has run the link is vanished and a real empty directory has been created.

Maybe this line from /var/log/foreman-installer/foreman.log helps:
[DEBUG 2020-04-22T09:34:41 main] Hook /usr/share/foreman-installer/hooks/boot/10-reset_foreman_db.rb returned #<Clamp::Option::Definition:0x000000018c5130 @switches=["--reset-foreman-db"], @type=:flag, @description="Drop foreman database first? You will lose all data! Unfortunately we\ncan't detect a failure at the moment so you should verify the success\nmanually. e.g. dropping can fail when DB is currently in use.", @default_value=false, @multivalued=nil, @attribute_name="reset_foreman_db"> [DEBUG 2020-04-22T09:34:41 main] Hook /usr/share/foreman-installer/hooks/boot/11-detailed_exitcodes.rb returned #<Clamp::Option::Definition:0x000000018cbfa8 @switches=["--detailed-exitcodes"], @type=:flag, @description="Provide transaction information via exit codes, see puppet-agent(8)\nfor full details.", @default_value=false, @multivalued=nil, @attribute_name="detailed_exitcodes">

After spending hours I am stuck again :frowning: Here just the first lines of the error messages:

if I ran “foreman-installer”

 /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: Failed to call refresh: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
 /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/errors.rb:157:in `fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/exec.rb:168:in `sync'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/exec.rb:626:in `refresh'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:147:in `process_callback'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:34:in `block in process_events'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:119:in `block in queued_events'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:118:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:118:in `queued_events'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/event_manager.rb:33:in `process_events'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:280:in `eval_resource'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:183:in `call'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:183:in `block (2 levels) in evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:519:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:518:in `thinmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:183:in `block in evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/graph/relationship_graph.rb:121:in `traverse'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:173:in `evaluate'
/usr/share/gems/gems/kafo-2.1.0/modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb:30:in `evaluate_with_trigger'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:239:in `block (2 levels) in apply'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:519:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:518:in `thinmark'

If a ran “foreman-rake db:migrate”

Apipie cache enabled but not present yet. Run apipie:cache rake task to speed up API calls.
rake aborted!
Sequel::Migrator::Error: More than 1 row in migrator table
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:619:in `schema_dataset'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:453:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:517:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:401:in `new'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:401:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/persistence_adapters/sequel.rb:261:in `migrate_db'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/persistence_adapters/sequel.rb:53:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:186:in `new'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:186:in `initialize_persistence'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:130:in `block (2 levels) in world_config'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/config.rb:42:in `method_missing'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/world.rb:28:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:78:in `new'

if I ran “foreman-rake apipie:cache:index”

Apipie cache enabled but not present yet. Run apipie:cache rake task to speed up API calls.
rake aborted!
Sequel::Migrator::Error: More than 1 row in migrator table
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:619:in `schema_dataset'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:453:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:517:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:401:in `new'
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-5.7.1/lib/sequel/extensions/migration.rb:401:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/persistence_adapters/sequel.rb:261:in `migrate_db'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/persistence_adapters/sequel.rb:53:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:186:in `new'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:186:in `initialize_persistence'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:130:in `block (2 levels) in world_config'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/config.rb:42:in `method_missing'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/world.rb:28:in `initialize'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.2.1/lib/dynflow/rails/configuration.rb:78:in `ne

Can someone explain me why this breaks:

[root@puppetmaster ~]# foreman-installer
 /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: Failed to call refresh: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
 /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/errors.rb:157:in `fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/exec.rb:168:in `sync'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/exec.rb:626:in `refresh'

But if I use only the command:
/usr/sbin/foreman-rake db:migrate

it is fine. No error messages appear…

Hi,

I did try the same process, leading to the same error concerning db, with foreman 2.3/katello 3.18.

Hey @bbarret

Will you please create your own thread with all your info, logs etc.
Have you tried upgrading to 2.5. It might solve your problems :wink:

Hello @mcorr !
Thanks for the suggestion.
i did encounter this because i wanted to “clone” a foreman/katello instance (version 2.3/3.18), to import content from the instance we daily use, and then perform upgrade.
I didn’t find such a “satellite-clone” nor such a “instance migrate” command in foreman.

in the logs we can see
foreman-rake-db:migrate]/unless: Password: su: Authentication failure