setting role variable used in 'when' not working as expected

I have the following defined in roles/apple/default/main.yml

epel_repo: true

I have the following defined in roles/apple/tasks/main.yml

  • command: rpm -Uvh {{ epel_url }}
    when: epel_repo

The load_driver already has epel installed so I am doing the following:

  • hosts: load_driver
    user: root
    vars_files:
  • vars/globals.yml
  • roles/stuff/defaults/main.yml
    roles:
  • { role: apple, epel_repo: false }

However, the following occurs:

19:59:01 TASK: [apple | command rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm] ***
19:59:01 failed: [load-driver] => {“changed”: true, “cmd”: [“rpm”, “-Uvh”, “http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm”], “delta”: “0:00:04.500043”, “end”: “2014-06-28 19:58:59.358809”, “item”: “”, “rc”: 1, “start”: “2014-06-28 19:58:54.858766”}
19:59:01 stderr: package epel-release-6-8.noarch is already installed
19:59:01 stdout: Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
19:59:01 Preparing… ##################################################
19:59:01
19:59:01 FATAL: all hosts have already failed – aborting

What am I doing wrong? There is a bunch of other stuff occurring in the role apple which I want to occur. I just want the rpm command not to execute.

Thanks.

Mike

Your RPM command returned a non-zero exit code, so that’s why it failed.

(I am curious if you are using rpm on OS X, that seems quite interesting…)

Ultimately though what you have shared shows it’s doing something with EPEL but you haven’t showed us any of the playbook to be able to tell if the playbook is written correctly or not, and it sounds like from the above there’s going to be something to sort out there.

Can you share the whole playbook or a minimal playbook that reproduces the problem via some example?

This is executing on centos.

I did include the following portion of the playbook:

  • hosts: load_driver
    user: root
    vars_files:
  • vars/globals.yml
  • roles/stuff/defaults/main.yml
    roles:
  • { role: apple, epel_repo: false }

The issue is I don’t think the “rpm -Uvh {{ epel_url }}” command should be executing at all as I have set “epel_repo: false” which means the “when: epel_repo” clause should cause the rpm command to be skipped.

Looks like this is my error. I didn’t push my changes…duh…