ansible/ansible — pull request #2679 by zbal (2013-04-14 11:26:26+00:00)
Title: Add dpkg module

Add support for dpkg command; --install and --remove

Packages can be specified either as a local deb file, or remote URL (http or ftp or .. it rely on urllib).

Idempotence is ensured by validating against the apt cache - a package that match the same name and version is not to be re-installed.

When a remote package is provided:
- the header of the file is fetched (the first 5k) and the ```control.tar.gz``` file is extracted to fetch the package info and avoid downloading the next 20MB
- an apt.package.Record is created from that file
- the cache is checked against installed versions.
- if the package is meant to be installed, the remaining part of the remote file is fetched (only 1 connection to the remote server is required)

Whichever a local or a remote .deb file is requested, a dependency check is performed against the apt-cache to ensure we don't install a broken package... A package is not installed if dependencies and their versions are not matching what is installed on the box. However ... if you specify force=yes in the arguments then it will be installed, then deal with it if this is breaking stuff...

Not to lie, I struggled with the partial download of a remote file to extract the .deb info, figure out the format, extract the embedded tar.gz but in the end .. I'm freaking happy of the result!