Host registration script fails with "dpkg: error: need an action option"

Problem:
It seems that for us, using the register host functionality to register Ubuntu machines to Foreman-Katello is failing.
When it installs the subscription-manager it reports: dpkg: error: need an action option
which is odd, as the command looks fine in my eyes, running it manually also works withoud issues and the script also then continues like normal.

I’ve seen this issue on a freshly 24.04 Ubuntu machine aswell, but can also easily reproduce it on a test machine. I’ve debugged it as far as i could and this is waht i found:

In the registration script, we get to this point:

      # rhn-client-tools conflicts with subscription-manager package
    # since rhn tools replaces subscription-manager, we need to explicitly
    # install subscription-manager after the rhn tools cleanup
    if [ x$ID = xol ]; then
      $PKG_MANAGER_REMOVE rhn-client-tools
      $PKG_MANAGER_INSTALL --setopt=obsoletes=0 subscription-manager
    elif [ -f /etc/debian_version ]; then
      echo Debug-Hello
      set -x
      $PKG_MANAGER_INSTALL subscription-manager
    fi

I’ve set that echo and set to show it in the logs below what happens when it fails:
## Running registration#Debug-Hello+ apt-get -o Dpkg::Options::='--force - Pastebin.com (it’s 80 lines, hence in pastebin).

Extract:

#
# Running registration
#
Debug-Hello
+ apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install -y subscription-manager
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common virt-what
Suggested packages:
  python3-subscription-manager-doc
The following NEW packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common subscription-manager virt-what
0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3406 kB of archives.
After this operation, 12.1 MB of additional disk space will be used.
dpkg: error: need an action option

Type dpkg --help for help about installing and deinstalling packages [*];
Use 'apt' or 'aptitude' for user-friendly package management;
Type dpkg -Dhelp for a list of dpkg debug flag values;
Type dpkg --force-help for a list of forcing options;
Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through 'less' or 'more' !
E: Sub-process /usr/bin/dpkg returned an error code (2)

When i add this line: apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install -y subscription-manager
directly into the script, just below the one that is made using variables:
apt-get -o Dpkg::Options::=‘–force-confdef’ -o Dpkg::Options::=‘–force-confold’ install -y subscription-manager
Log: ## Adding repository#Ign:1 https://foremandirectlyurltogetsubscriptoin-man - Pastebin.com
Extract:

#
# Running registration
#
Debug-Hello
+ apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install -y subscription-manager
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common virt-what
Suggested packages:
  python3-subscription-manager-doc
The following NEW packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common subscription-manager virt-what
0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3406 kB of archives.
After this operation, 12.1 MB of additional disk space will be used.
dpkg: error: need an action option

Type dpkg --help for help about installing and deinstalling packages [*];
Use 'apt' or 'aptitude' for user-friendly package management;
Type dpkg -Dhelp for a list of dpkg debug flag values;
Type dpkg --force-help for a list of forcing options;
Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through 'less' or 'more' !
E: Sub-process /usr/bin/dpkg returned an error code (2)
+ echo Debug-Novars
Debug-Novars
+ apt-get -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install -y subscription-manager
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common virt-what
Suggested packages:
  python3-subscription-manager-doc
The following NEW packages will be installed:
  apt-transport-go-katello libfsverity0 liblua5.3-0 librpm9t64 librpmbuild9t64 librpmio9t64 librpmsign9t64 python-dmidecode-data python3-dateutil python3-decorator
  python3-dmidecode python3-iniparse python3-libxml2 python3-rpm python3-subscription-manager rpm-common subscription-manager virt-what
0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3406 kB of archives.
After this operation, 12.1 MB of additional disk space will be used.
Selecting previously unselected package apt-transport-go-katello.
(Reading database ... 128225 files and directories currently installed.)
Preparing to unpack .../00-apt-transport-go-katello_0.1.0-1_amd64.deb ...

It’s super weird, i’ve also updated to the latest foreman version just to be sure, as we came from rc1.
I’ve implemented a workaround to run the script and if it fails, to manually install subscription-manager and invoke it again.
That’s sufficient, but assuming this also happens in your test env/elsewhere, it’s smth i would like to help diagnose and fix :slight_smile:

Expected outcome:
Registration script is run, and the host registers.

Foreman and Proxy versions:
Version 3.15.0 © (we don’t have proxies)

Foreman and Proxy plugin versions:

Name Description Author Version

foreman-tasks 11.0.0

foreman_ansible 16.0.0

foreman_azure_rm 3.0.3

foreman_discovery 11.0.1

foreman_remote_execution 16.0.3

foreman_rh_cloud 12.1.0

katello 4.17.0.rc1

puppetdb_foreman 6.0.2

Distribution and version:
Red Hat Enterprise Linux 9.6 (Plow)

Other relevant data:
As shown above:
We do make sure to offer the repo’s of Ubuntu and atix repo’s internally, the script adds these automatically and is also able to download/install what it needs before it’s registered.
Current output: ## Running registration#Debug-Hello+ apt-get -o Dpkg::Options::='--force - Pastebin.com
Adjusted script output using no variable for installing subscription-manager logs: ## Adding repository#Ign:1 https://foremandirectlyurltogetsubscriptoin-man - Pastebin.com
We also make sure to daily have the latest updates available.

Nobody else has this problem?

Yes, I just ran into this exact error registering a Debian 12 host. I recently updated to 3.15.0. This is the first Debian based host I’ve attempted to register since that update. So I’m a bit stumped.

Hm, i’ve added a bypass in our playbook to simply install the subscription-manager manually if the command fails, and then if that succeeds it retries the registration again.

I can’t promise when i can get to it, but i definitly want to go through that script and see why this happens. The only thing i can imagine that there’s something going wrong with setting the variables somehow.

PR 10436 – this update to the pkg_manager snippet seems to have broken things.

-o Dpkg::Options::='--foo should be -o Dpkg::Options='--foo'

1 Like

Yes, that is what I’m seeing as the culprit. Installing the subscription manger components prior to registration is a workaround, as @Macley pointed out.

I looked at Fixes #38200 - use apt options for install by sbernhard · Pull Request #10436 · theforeman/foreman · GitHub but i don’t see a missing ’ anywhere. Even in code i don’t see anything odd like missing a quote or double quote.

Sorry, I had a typo in my post. It’s the extra double colon after “options” that’s the issue.

Can you link which line in the source tree? Or submit a PR because i really can’t see where the typo is being made
like i would say the issue must be here as this is what is being used?

@bruchio and @bhill i understand now what you two meant, and removed the single quote’s from the install arguments part of the script for debian.
Have a look here: Adjust apt options for install so registration templates works again by Macleykun · Pull Request #10594 · theforeman/foreman · GitHub

I’ll add another update here once i found the place in our foreman installation to apply a more proper workaround then what i suggested before.

In: /usr/share/foreman/app/views/unattended/provisioning_templates/snippet/pkg_manager.erb
on line 32
PKG_MANAGER_INSTALL="${PKG_MANAGER} -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install -y"
change that to
PKG_MANAGER_INSTALL="${PKG_MANAGER} -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install -y"

Now restart foreman-katello: foreman-maintain service restart

If you fetch the script fresh, it will have those quote’s removed and your registration will work as normal again!

@Macley thank you for your efforts on this!

1 Like