Subsequent play do not runs when upper one fails

12 views
Skip to first unread message

amit ahuja

unread,
Apr 10, 2019, 12:02:06 PM4/10/19
to ansible...@googlegroups.com
Hi,

i have a condition where lower plays don't get executed when upper play fail on some condition . i need to run my second play also inside same yml file if  above play gets fail, how can i do this ?? play with localhost group dont get executed. 

my play looks like below- 

---
- hosts: redhat
  vars_files:
    - group_vars/redhat.yml
  tasks:
  - debug:
        msg: "{{ file }}"
  - fail: msg="failing"
    when: file == 'abc'

- hosts: localhost
  tasks:
  - name: execute command
    shell: hostname
    register: result

  - debug:
      msg: "{{result}}"

*******************O/P ***********************

[admin@ansible-poc ansible]$ ansible-playbook redhat.yml

PLAY [redhat] **********************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [169.144.61.82]

TASK [debug] ***********************************************************************************************************************************************************
ok: [169.144.61.82] => {
    "msg": "abc"
}

TASK [fail] ************************************************************************************************************************************************************
fatal: [169.144.61.82]: FAILED! => {"changed": false, "msg": "failing"}
        to retry, use: --limit @/home/admin/ansible/redhat.retry

PLAY RECAP *************************************************************************************************************************************************************
169.144.61.82              : ok=2    changed=0    unreachable=0    failed=1

Brian Coca

unread,
Apr 18, 2019, 12:30:50 PM4/18/19
to Ansible Project
put the previous play in a block and use 'rescue' to avoid total play faliure

by design if a play fully fails, it terminates the current run


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages