Hi,

I have 3 host in my inventory group as below
Inventory:-
==========
---
all:
  children:
    dse_layer_7:
      hosts:
        XXXXX:
        XXXXX:
        XXXXX:
      vars:  
        ansible_user: XXXX
        ansible_connection: ssh
        ansible_password: "{{ lookup('file', 'XXXXXX) }}"


Scenario: - Want to run the below command on first host and if the command 
executed successfully skip the rest of the host. If it fails on first host 
,command should run on second host and if the command executed successfully 
skip the rest of the host and so on.

command:-
=========
nodetool -u controlRole -pw '{{ controlRole_dse_layer7_pass }}' status | grep 
-A 10 {{ dse_layer_7_datacenter_name }}


so to achieve this  i wrote the playbook as below, which is working fine 
with warnings .In azure pipeline this warning is considered as failure.
Playbook:-
=============
---
- name: Check the status of DSE layer 7 cluster
  hosts: XXXX
  gather_facts: False
  serial: 1
  tasks:
    - meta: end_play
      when: "{% for item in hostvars.values() %}{% if 
item.MyDoneVar|default(False) %}True{% endif %}{% endfor %}"
    - name: nodetool status playbook execution
      import_role:
        name: ../roles/dse/nodetool_status_check

Role:-
=========
---
- name: Nodetool status for DSE layer 7 cluster
  block: 
    - name: Nodetool Status
      shell: nodetool -u controlRole -pw '{{ controlRole_dse_layer7_pass }}' 
status | grep -A 10 {{ dse_layer_7_datacenter_name }}
      register: result_nodetool
   - set_fact:
         MyDoneVar: True

On Tuesday, August 10, 2021 at 12:24:30 PM UTC+5:30 [email protected] 
wrote:

> On Tue, 10 Aug 2021 at 07:54, Mahesh Nalavade
> <[email protected]> wrote:
> >
> > Hi Racke,
> >
> > Can you please help me to form the logic as you suggested above for 
> below condition
>
> Instead of reverse engineering/guessing, why not tell us what you
> actually had in mind when you added that condition?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/152a9aaa-9f5b-4b3c-9bc7-e4a11d8dc78fn%40googlegroups.com.

Reply via email to