You might also look at changed_when or failed_when. Here are some examples.

https://www.middlewareinventory.com/blog/ansible-changed_when-and-failed_when-examples/

On 11/10/21 04:24, Roberto Paz wrote:
You should check "end_play":


- block:
- name: Closing tasks
...
- meta: end_playwhen: vlan_not_present_condition

This will end the playbook completely.

El miércoles, 10 de noviembre de 2021 a la(s) 00:18:44 UTC-6, aksha...@gmail.com escribió:

    Hi Guys,
    I want to add a condition to stop execution of playbook if "vlan
    not found". I am attaching my playbook tasks below:

      - name: check vlan availability
        ios_command:
          commands:
            - show vlan id {{ vlan1 }}
        register: precheck

      - name: check voice_vlan availability
        ios_command:
          commands:
            - show vlan id {{ vlan2 }}
        register: precheck_voice_vlan

      - name: L2 Vlan1 Availability Check
        debug:
          msg: "Vlan not present in the switch"
        when: "'not found' in precheck"

      - name: L2 Vlan2 Availability Check
        debug:
          msg: "Vlan not present in the switch"
        when: "'not found' in precheck_voice_vlan"

    ===========here I want stop playbook execution if vlan not
    found========

      - name: get interface status from the device
        ios_command:
          commands:
            - show run int {{ interface }} | i trunk
        register: precheck_int

    if Vlan not found in precheck I want to stop further execution
    .Please help me for this.

--
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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b7a889f1-0c32-4729-a05e-62250d1ff750n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/b7a889f1-0c32-4729-a05e-62250d1ff750n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Jack Morgan

--
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8d19b9db-ec9b-85cd-7698-1469b4d2ba33%40jento.io.

Reply via email to