conditional roles

Is this normal/expected?

I am trying to use conditional roles, and once it hits a negative condition, it skips every role afterwards:

     - hosts: all
       roles:
         - common
         - role: AppDynamics
           when: appdynamics
         - java

"appdynamics" is loaded as True/False from a group_vars, and is different depending on the environment loaded (different inventories, group_vars etc... for PROD vs. TEST vs. DEV).

With the playbook above, the java role is skipped when appdynamic is False. If I move the java role above the AppDynamics role, then the java role never gets skipped.

Should the condition affect roles after it?

Thanks.

I’m not sure you’re seeing what behavior you think you are seeing.

When just applies the conditional to each task.

It’s also a confusing (and noisy output) way to organize things, which is why we don’t encourage it.

it’s much better to do this:

  • hosts: AppDynamics
    roles:
  • AppDynamics

I was just looking to do the same thing. Michael’s post clued me into what I was missing.

Specifically, I hadn’t realized you can list your hosts more than once in the hosts file. That makes a site.yml file similar to:

  • hosts: roleA
    roles:

  • roleA

  • hosts: roleB
    roles:

  • roleB

Work to give you the same effect as we wanted with conditional roles. Just list the host under all the roles you want it to have in the groups file.

Thanks Michael!