With_items over the loops with "when", can we write multiple "when" in one task?

Hi all,

I want to write the code like this, is it possible? or is there any better way to write?

Hi all,

I want to write the code like this, is it possible? or is there any better
way to write?

Why don't you try to see if it works?

---
- become: true
  become_user: wsadmin
  hosts: ATST-ESBDMGR
  tasks:
    -
      ping: ~
    -
      name: "Displaying Hostname for DMGR Profile Server"
      register: hostnamefordmgr
      shell: hostname
    -
      debug: var=hostnamefordmgr.stdout_lines
    -
      name: "All clusters status in This Server"
      shell: "{{ command to execute script for clusters status }} cluster1
cluster2 cluster3 cluster4 cluster5 cluster6"
      register: allcluster_status
    -
      debug: var=allcluster_status.stdout_lines
    -
      name: " Starting the clusters which is stopped"
      shell: "{{ script to start cluster}] {{item.cluster1}}
{{item.cluster2}} {{item.cluster3}} {{item.cluster4}} {{item.cluster5}}
{{item.cluster6}} "
      when: "'cluster1 started' in allcluster_status.stdout"
          with_items:
              - { cluster1: 'cluster1 name' }
      when: "'cluster2 started' in allcluster_status.stdout"
          with_items:
              - { cluster2: 'cluster2 name' }
      when: "'cluster3 started' in allcluster_status.stdout"
          with_items:
              - { cluster3: 'cluster3 name' }
      when: "'cluster4 started' in allcluster_status.stdout"
          with_items:
              - { cluster4: 'cluster2 name' }
      register: startclusterstatus
    -
      debug: var=startclusterstatus.stdout_lines

But no, you can't, you can only have one when and one with_items per task.

The 'when' is executed PER item from with_, so you do have that, but
written in single keyword, you cannot do multiple keywords.

when: '"%s started" % item.key in allcluster_status.stdout'
with_dict:
    cluster1: cluster1 name
    cluster2: cluster2 name
....

Raj Martha [15.05.2017 16:40]:

    -
      debug: var=allcluster_status.stdout_lines
    -
      name: " Starting the clusters which is stopped"
      shell: "{{ script to start cluster}] {{item.cluster1}}

the {{ do not match the }] here!

HI Coca,

some reason the play skipping even though there is a “started” word in allcluster_status.stdout, can you please give me exact “when”
this is what i have