Enabling ansible plugin results in failure of db:migrate

Problem: When I enabled ansible plugins in installer and run installer I get and error for foreman-rake task db:migrate.

Expected outcome:
It should install plugins and make all database migrations without errors
Foreman and Proxy versions:
foreman 3.1
Foreman and Proxy plugin versions:
ansible plugin 3.x
Distribution and version:
Rocky Linux 8.5
Other relevant data:
foreman-rake db:migrate gives

PG::UndefinedTable: ERROR:  relation "ansible_roles" does not exist
LINE 8:  WHERE a.attrelid = '"ansible_roles"'::regclass

And foreman process no longer works, also if I try to add manually the relation I get

Caused by:
ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR:  relation "ansible_roles" already exists

I had the same problem, I’ve managed to workaround the problem using the version 6.4 of the package rubygem-foreman_ansible.

I was comparing the files of directory db/migrate between 7.0 and 6.4 and a lot things was added in the new version, but I do not know enough either Ruby or PostgreSQL to be certain in which file the issue is.

Will try and come back, thanks !!

I also had this same issue - the workaround (downgrade to rubygem-foreman_ansible-6.4.1-1.fm2_6.el8.noarch) works for me.

great, good to hear that.

I found the problem and a workaround as my colleague @Crited ran in the same problem, for solutions perhaps @ezr-ondrej or @Ondrej_Prazak can have a look as the code owners.

When running the migration I recognized the GraphQL code added with 7.0.0 is trying to accessing the not initialized database, so I did the following:

mv /usr/share/gems/gems/foreman_ansible-7.0.2/app/graphql /tmp
vi /usr/share/gems/gems/foreman_ansible-7.0.2/lib/foreman_ansible/register.rb (comment the block related to graphql)
foreman-rake db:migrate
mv /tmp/graphql /usr/share/gems/gems/foreman_ansible-7.0.2/app/
vi /usr/share/gems/gems/foreman_ansible-7.0.2/lib/foreman_ansible/register.rb (remove the comment so the code)

So it looks like this problem will hit every fresh installation but not upgrades from older versions.

Afterwards I had another problem that the installer did not restart Foreman so the plugin was loaded before the smart proxy tried to register the feature so it failed and required some manual steps again, but now it looks fine.


I’m sorry not noticing this earlier, but this had been already reported as RM#34366 and workaround has been merged in foreman#9080 and also cherry-picked into 3.1 stable.

The workaround will be released in 3.1.2 and 3.2.0 releases, proper fix should be fixing how we are loading the GraphQL classes, but this will at least allow fresh installs to work.

1 Like

Thanks a lot, I did not find the patch.
Hope was pinging the right person would help and I was not disappointed as always! :slight_smile:

Thank you for sharing this. I was running into the same problem while trying to add a different plugin. (leapp) I was able to use the workaround you provided to get the plugin to install successfully. I was also able to install the openscap plugin after the workaround, where I was getting the same error prior to finding your post. Many thanks. (Foreman 3.1 / Katello 4.3 on RHEL 8)

Thank you for the workaround ! Worked for me on Debian 10 trying to add Ansible plugin.