Scotty, we have no power! Debian backports

Back to the future film logo

After our first steps with Ansible, we will be willing to configure even the coffee machine with Ansible, moreover if we install coffee machines very often, so it's time to start wandering through internet and search how we can do more things, let us imagine we want to install dbmail (thing that we will be doing later), our first step should be adding dbmail's repository (http://debian.nfgd.net/debian), this can be easily done with this playbook:

- hosts: dbmail-all
  user: ansible
  sudo: yes
  tasks:
    tasks:
  - name: add Dbmail repositories
    apt_repository: repo={{item}} state=present
    with_items:
      - deb http://debian.nfgd.net/debian jessie main
      - deb-src http://debian.nfgd.net/debian jessie main

And when we happily try to run our playbook we found out the following:

ERROR: repo is not a legal parameter in an Ansible task or handler

What the...? But since repo is a mandatory label for apt_repository, How can this parameter be illegal? The answer is: Ansible's outdated version, that's it, default version in Debian Jessie is 1.7.2 while last stable version in Github is 2.2, and that's a biiiiiig difference.

So we need to add backports in Jessie (Debian way), to do so we create a new file: /etc/apt/sources.list.d/001_jessie_backports.list:

deb http://httpredir.debian.org/debian jessie-backports main contrib non-free

This way, we can do apt-get update and see:

Get:1 http://httpredir.debian.org jessie-backports InRelease [166 kB]
Get:2 http://httpredir.debian.org jessie-backports/main amd64 Packages [791 kB]
Get:3 http://httpredir.debian.org jessie-backports/contrib amd64 Packages [9,804 B]
Get:4 http://httpredir.debian.org jessie-backports/non-free amd64 Packages [27.7 kB]

So we have now backports sources available and will be able to use them to install packages, you need to know you'll be still installing packages from Jessie's default repositories unless you force the installation from backports:

apt-get install -t jessie-backports ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
ieee-data python-kerberos python-netaddr python-xmltodict
Suggested packages:
cowsay ipython python-netaddr-docs
Recommended packages:
python-winrm
The following NEW packages will be installed:
ieee-data python-kerberos python-netaddr python-xmltodict
The following packages will be upgraded:
ansible
1 upgraded, 4 newly installed
...
Setting up python-xmltodict (0.9.0-1) ...
Setting up ieee-data (20150531.1~deb8u2) ...
Setting up python-netaddr (0.7.18-1~bpo8+1) ...
Setting up ansible (2.2.0.0-1~bpo8+1) ...
Installing new version of config file /etc/ansible/ansible.cfg ...
Setting up python-kerberos (1.1.5-0.1+deb8u1) ...

Doing so we have now ansible 2.2.0 installed and now we can run our playbook as intended:

PLAY [dbmail] ******************************************************************

TASK [setup] *******************************************************************

ok: [10.0.15.13]

TASK [adding Dbmail repositories] *******************************************
changed: [10.0.15.13] => (item=deb http://debian.nfgd.net/debian jessie main)
changed: [10.0.15.13] => (item=deb-src http://debian.nfgd.net/debian jessie main)

PLAY RECAP *********************************************************************
10.0.15.13 : ok=2 changed=1 unreachable=0 failed=0