Attempting to combine sub_items and when for application deployment

I’m trying to deploy specific Java EE EARs to a host based on what groups that host is in.

Each EAR goes in to it’s own deployable directory because we’re running each application component in it’s own container.

What I have is:

  • name: Copy EAR
    copy:
    src: “{{ maven }}/au/com/company/{{ item.1.name }}/{{ item.1.version }}/{{ item.1.name }}-{{ item.1.version }}.ear”
    dest: /opt/company/{{ item.0.name }}/deployments/{{ item.1.name }}.ear
    with_subelements:
  • deployables
  • ears
    when: item.0.name in group_names

with the variables file containing:

maven: “{{ lookup(‘env’, ‘HOME’) }}/.m2/repository”

deployables:

  • application: catalogue
    ears:
  • { name: ‘catalogue-ear’, version: ‘0.2.0-SNAPSHOT’ }

which gives the error:

fatal: [local-int] => error while evaluating conditional: item.0.name in group_names

What I had hoped would happen is if this host is in the catalogue group then the catalogue EAR would be copied in to the specified directory.

Is the ‘in’ operator not supported here, or am I missing something really obvious? Is there a better way to do this?

Thanks,

Lyle

What does your group_names variable look like?

For that machine it should be [‘catalogue’, ‘catalogue-db’, ‘feeds-db’, ‘fulfilment’, ‘fulfilment-db’, ‘ungrouped’].

I don’t know why ‘ungrouped’ ends up on there, it isn’t something I added, but I see it appear in earlier steps.

Classic PEBKAC. It should have been item.0.application instead of item.0.name.

Amazing how easily you figure things out when you spend time away from them.