Installing PostgreSQL 9.2 on a Debian/Ubuntu box using fabtools

Here is a quick recipe to install the latest stable PostgreSQL version on a server using fabtools.

    from fabric.api import task

    import fabtools
    from fabtools import require

    def postgresql():
        Install the latest stable PostgreSQL version on Debian/Ubuntu
        from the PostgreSQL Global Development Group APT repository


        # Get the distrib codename
        # Note that with fabtools >= 0.14.0 this will be:
        #   distrib = fabtools.system.distrib_codename()
        distrib = fabtools.deb.distrib_codename()

        # Add the PGDG key
        fabtools.deb.add_apt_key('ACCC4CF8.asc', update=False)

        # Add the PGDG repository
            '%s-pgdg' % distrib,

        # Install PostgreSQL

Recipe tested on Ubuntu 12.04 (precise) and Debian 6.0 (squeeze).