Use Ansible to change dependency in Debian package

Install software on Debian or Ubuntu is very easy with .deb package file. But sometimes dependencies can't be resolved and software install failed. Most of the time it's possible to fix this issue by editing the dependencies list. Because command are long and ambigous I propose here an Ansible role to achieve it.

For this blog post, I will use Slack package with Debian 11 (Bullseye). I also got same kind of trouble with Insomnia.

This is what happened when I'm trying to install Slack

root@orion:/root# dpkg -i slack-desktop-4.22.0-amd64.deb
Selecting previously unselected package slack-desktop.
(Reading database... 122646 files and directories currently installed.)
Preparing to unpack slack-desktop-4.22.0-amd64.deb ...
Unpacking slack-desktop (4.22.0) ...
dpkg: <code>dependency problems prevent configuration of</code> slack-desktop:
 slack-desktop depends on libappindicator3-1 ; however:
  Package libappindicator3-1 is not installed.
 

The issue is that package libappindicator3-1 doesn't exist in Debian 11 with this name. It's named libayatana-appindicator3-1. So we need to change slack package to rename this dependency.

The first step is to download .deb file from Slack, I chosed /opt as working directory.

- name: download slack
  get_url:
    url: https://downloads.slack-edge.com/releases/linux/4.22.0/prod/x64/slack-desktop-4.22.0-amd64.deb
    dest: /opt/slack-desktop.deb
    owner: root
    mode: 0644

Then we will unpack it and check it using dpkg-deb utility.

- name: unpack slack deb
  command: "dpkg-deb -x slack-desktop.deb unpack"
  args:
    chdir: /opt

- name: control slack deb
  command: "dpkg-deb --control slack-desktop.deb"
  args:
    chdir: /opt

We obtain two directories DEBIAN/ and unpack/. To repack the package we will need the DEBIAN/ dir inside the unpack/ dir, so let's move it.

- name: rename unpack deb
  command: "mv DEBIAN unpack"
  args:
    chdir: /opt

Then we need to edit control file to change dependency name. "replace" module of ansible is perfect for this task.

- name: replace dependency
  replace:
    path: /opt/unpack/DEBIAN/control
    regexp: 'libappindicator3-1'
    replace: 'libayatana-appindicator3-1'

So now we just have to repack everything to get a new .deb file.

- name: repack deb
  command: "dpkg -b unpack/ slack-fixed.deb"
  args:
    chdir: /opt

Et voilà, debian package have the right dependencies, we can install it and clean the work.

- name: install slack
  apt:
    deb: /opt/slack-fixed.deb

- name: clean slack
  command: "rm -Rf /opt/slack-fixed.deb /opt/unpack /opt/slack-desktop.deb"
 

I keep this example simple without variable to let it easy to understand.

Add a comment