Dynamic variables includes in roles

This should be simple but I cant figure it. I want to read in a list of packages to install dependent on the os major version. However I want to do this at the role level.

eg

I have 3 package lists, one for RHEL5, one for RHEL6 machines and one for RHEL7 machines. I want to dynamically pick the one I want depending on what the target machine is with something below. I could duplicate the action below 3x and condition it with a when, but surely there must be a more elegant way than that?

  • name: install packages
    action: yum
    name={{item}}

state=present
tags:

  • packages
    with_items:
  • “{{packages}}”

I have monkeyed around with the playbook with includes but none seem to work. I’m on ansible 2.x (latest from pip), but cannt seem to figure this right now, and I keep gettting the following which isnt overly helpful (adding -vvvv, doesnt reveal much more)

TASK [ora_pre : install packages] *********************************
task path: /usr/local/ansible/roles/ora_pre/tasks/main.yml:39
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error… This feature will be removed in a future release. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

playbook attempts