Collectd - manual install from source - only if a new package is not available

Hello
I have a role for installing Collectd agent.

To get the Riemann plugin, I need version 5.4.0 or above.
The following works fine on Ubuntu 14.x

`

  • apt: pkg={{ item }} state=present update_cache=yes cache_valid_time=600
    with_items:
  • collectd=5.4.0

`

But, Ubuntu 12.x does not have the latest collectd, so I’m using a manual process:

`

  • name: Download Collectd
    `
    get_url: url={{collectd_url}}{{collectd_version}}.tar.gz dest=“/home/{{login_user}}/”
    register: new_archive

  • name: Unarchive source
    unarchive:
    src=“/home/{{login_user}}/{{collectd_version}}.tar.gz”
    dest=“/home/{{login_user}}/”
    copy=no
    when: new_archive|changed

  • name: confgiure
    shell: ./configure
    args:
    chdir: /home/{{login_user}}/{{collectd_version}}

  • name: make
    sudo: yes
    shell: make all install
    args:
    chdir: /home/{{login_user}}/{{collectd_version}}

So my question:
How to keeping using the apt-get when 5.4.0 is available and install from source when its not?

Thanks

Do yourself a favour and build a Deb with FPM, it's pretty straightforward.