6 Enable multiverse on Ubuntu
lorin edited this page 2012-10-30 09:49:32 -07:00

Some Ubuntu packages require the "multiverse" component (e.g., ec2-api-tools). Here's a simple playbook that enables multiverse and installs the ec2-api-tools package.

- hosts: all
  sudo: True
  gather_facts: True

  tasks:
  - name: ensure multiverse component is enabled
    apt_repository: repo="deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ $item multiverse"
    with_items:
      - ${ansible_distribution_release}
      - ${ansible_distribution_release}-updates
      - ${ansible_distribution_release}-security

  - name: ensure EC2 API tools are installed
    apt: pkg=ec2-api-tools update-cache=yes

Some notes about this:

  • This uses the Ubuntu package archive hosted on EC2, so it may only work on Ubuntu instances running inside of EC2. Otherwise, adjust the URL in the apt_repository line accordingly.
  • The gather_facts option must be set to True so that the ansible_distribution_release variable gets set. Note that gather_facts defaults to True, so it isn't actually necessary to set it explicitly like this. The ansible_distribution_release variable contains the codename of the Ubuntu distribution (e.g., precise for 12.04).
  • You need to set update-cache=yes when installing the first package from multiverse, so that apt retrieves the package information from the multiverse before trying to install the package. This is equivalent to doing an "apt-get update".
  • The deb-src entries will automatically be added to /etc/apt/sources.list, you do not need to add them explicitly. See the apt_repository module docs for more details.