Counting and Displaying no of Successful and Failed Task in a playbook

9 views
Skip to first unread message

Vino B

unread,
May 26, 2018, 9:15:27 AM5/26/18
to Ansible Project
Hi All,

  I have a play book, i need a help on how to display no of failed and successfull task as the out always , 

PLAY RECAP *************************************************************************************************************************************************************
server1              : ok=5    changed=0    unreachable=0    failed=0
server2              : ok=5    changed=0    unreachable=0    failed=0

Example:
PLAY RECAP *************************************************************************************************************************************************************
server1              : ok=5    changed=0    unreachable=0    failed=0     task_succeed=4     task_failed=1
server2              : ok=5    changed=0    unreachable=0    failed=0     task_succeed=3     task_failed=2


- hosts: all
  become: true
  become_method: sudo
  gather_facts: no
  vars:
    failed_count: 0
  vars_files:
  - "/home/ansible/.ansible/target.yml"
  tasks:
  - name: Check the status of Kerbros Service
    shell: /bin/systemctl status {{ item.tname }} | /usr/bin/head -1
    with_items:
      - { tname: 'rpc-gssd.service' }
      - { tname: 'rpc-svcgssd.service' }
      - { tname: 'nfs-idmapd' }
    register: kerbros_status
    failed_when: kerbros_status.rc != 3
    changed_when: false
    ignore_errors: True
    tags: kerbros
  - name: Increment variable
    set_fact: failed_count={{ failed_count | int + 1 }}
    when: kerbros_status.failed


From,
Vino.B

Reply all
Reply to author
Forward
0 new messages