Recently I’ve been doing a bit of work to port a number of chef cookbooks to ansible. Most of the chef stuff was developed for specific one off deployments, and so generally didn’t provide multi distributions at all. I thought I’d take this as an opportunity to give the ansible versions fairly solid support across the most common variations that I use frequently, which is basically CentOS and Ubuntu. I use fedora as a desktop, and have a couple of Debian boxes, so I might as well do them at the same time.

However the result of this is that I’ve spent the last week or so digging around in the various packaging formats and repository styles that each distro uses. I thought it would be worth recording the commands that I found most useful for common usages.

Which package provides a particular file?

A common case is logging into a machine and finding a particular utility or config file, but not being familiar with its source. So the assumption here is that the file was provided by a package that has been locally installed already.

RedHat based distros have this;

$ rpm -q --whatprovides `which htpasswd`
httpd-tools-2.2.15-60.el6.centos.6.x86_64

The debian/ubuntu equivalent is

$ dpkg -S `which htpasswd`
apache2-utils: /usr/bin/htpasswd

List the files provided by an installed package

$ rpm -ql httpd-tools
/usr/bin/ab
/usr/bin/htdbm
/usr/bin/htdigest
...

The debian/ubuntu equivalent is

$ dpkg -L apache2-utils
...
/usr/bin/htdbm
/usr/bin/htdigest
/usr/bin/htpasswd
...

List the files in a package that has not been installed?

For machines of the vintage that I have been working with, (centos-6. centos-7, debian-8) etc, the basic apt and yum tools do not support querying file lists from the remote repo out of the box. CentOS requires the yum-utils package and Debian 8 required apt-file. Once installed you can do this;

$ repoquery -l httpd-tools
...
/usr/bin/ab
/usr/bin/htdbm
/usr/bin/htdigest
...

The debian/ubuntu equivalent (once apt-file is installed)

$ apt-file list apache2-utils
...
apache2-utils: /usr/bin/htdbm
apache2-utils: /usr/bin/htdigest
apache2-utils: /usr/bin/htpasswd
...

Search for packages with version information included

The output from yum search XXX is pretty basic, no versions, no installed status. The alternative is to use list instead which also provides the repo and blocks them into “Installed” or “Available”

$ yum list php-*
Installed Packages
php.x86_64                     5.3.3-49.el6           @base
php-cli.x86_64                 5.3.3-49.el6           @base
...
Available Packages
php-Analog.noarch              1.0.0-3.git9ab4c9e.el6 epel 
...

The debian/ubuntu equivalent is

$ apt list php*
...
/usr/bin/htdbm
/usr/bin/htdigest
...

Although the output formatting is a little bit unhelpful

Task Debian RedHat
What provides file? dpkg -S which htpasswd rpm -q –whatprovides which htpasswd
Uninstall Package apt remove yum remove