Search code examples
ansibleansible-2.x

How to filter Play Recap after run Playbook in Ansible


I'm new to Ansible and i'm using it for a project where i run my playbook in 1024 hosts. I managed to get my playbook running well but right now i need a way to filter the Play Recap that's showed after running the playbook.

PLAY RECAP ********************************************************************************************

100.80.80.1                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.3                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.4                : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
100.80.80.5                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.6                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.7                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.8                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2
100.80.80.9                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=2

This is a example of what it shows in my Play Recap, in this example i have only 8 hosts so it's easy to see what host changed or failed, the problem it's when i run my real playbook over the 1024 hosts and my play recap goes to 1024 lines and it's almost impossible to go reading every line to see what changed or failed.

So my question is, how do i filter the Play Recap to only show changed and failed hosts? Hiding OK and Skipped

I tried to use "display_skipped_hosts= False" and "display_ok_hosts= False" in my ansible.cfg but nothing changes.

Appreciate the help!


Solution

  • Thanks for the help guys!

    I find a solution for what i need and here goes the instructions for anyone with the same need as i.


    cd /etc/ansible/playbooks
    ansible-playbook (playbook_name).yaml | tee /etc/ansible/log/$(date +'%Y.%m.%d-%H.%M').txt
    

    I go to my playbooks directory and exec my playbook using "tee" to set a specific log file


    cd /etc/ansible/log
    sed -n '/PLAY RECAP/,/-0300/p' (log_name).txt | grep -v "ignored=2"
    

    Then i go to directory of my file and using the command sed along with grep i filter only the lines with actual changes in hosts because it's what i needed, but you can tweak for your needs.


    And that is it! You should see a output like that:

        PLAY RECAP *********************************************************************
    100.80.80.4                : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
    
    Playbook run took 0 days, 0 hours, 0 minutes, 19 seconds
    

    That way i solved two problems at once which was a way to filter changed hosts and a way to have one log per playbook run.