# Create a list of Failed tasks

**URL:** <https://forum.ansible.com/t/create-a-list-of-failed-tasks/34095>\
**Category:** Ansible Project\
**Created:** [October 23, 2020, 7:47pm UTC](https://forum.ansible.com/t/create-a-list-of-failed-tasks/34095 "2020-10-23T19:47:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jason/32/304_2.png) [@Jason](https://forum.ansible.com/u/Jason)\
**Post date:** [October 23, 2020, 7:47pm UTC](https://forum.ansible.com/t/create-a-list-of-failed-tasks/34095/1 "2020-10-23T19:47:45Z")

</div>

Hello,

I am trying to get a list of devices that are out of compliance with Cisco licensing. I would like to take failed out of compliance devices and add them to a list. Then send it to Microsoft Teams.

What I am looking for is a list to just send to Teams once, instead of trying to send multiple calls for each failure. Teams does not like it when you make multiple calls in quick succession.

The way that I am currently doing it is taking the host name and splitting each letter and joining with a comma. This was just my last attempt. I also tried with\_items but it seems to just be tied to each host and not a global variable. Which makes sense in most cases… Any help would be appreciated.

- name: Get License Information  
cisco.ios.ios\_command:  
commands: “show license summary”  
register: license3

- name: Assert that it is registered and authorized  
block:

- name: Asset that it is authorized  
assert:  
that:

- “‘Status: AUTHORIZED’ in license3.stdout[0]”  
fail\_msg: “Device is not Authorized”  
success\_msg: “Device Authorized”  
rescue:

- name: Add the device to the OOC list  
set\_fact: #### This is the piece that does not work.  
OOC: “{{ inventory\_hostname | join(', ') }}”

- name: Send a team message of OUT OF COMPLIANCE devices  
uri:  
url: “webhook”  
method: POST  
status\_code: 200  
body\_format: json  
body: |  
{  
“title”: “Smart License Out of Compliance Devices”,  
“text”: “{{ OOC }},”  
}  
run\_once: True  
tags: notifications

- name: Debug  
debug:  
var: OOC  
verbosity: 0  
run\_once: True

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 23, 2020, 9:35pm UTC](https://forum.ansible.com/t/create-a-list-of-failed-tasks/34095/2 "2020-10-23T21:35:44Z")

</div>

Set variable OOC\_status in the block and use it to select the list of  
the hosts. See the inline code below (not tested)

> I am trying to get a list of devices that are out of compliance with Cisco  
> licensing...
> 
> &nbsp;&nbsp;- name: Get License Information  
> &nbsp;&nbsp;&nbsp;&nbsp;cisco.ios.ios\_command:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commands: "show license summary"  
> &nbsp;&nbsp;&nbsp;&nbsp;register: license3
> 
> &nbsp;&nbsp;- name: Assert that it is registered and authorized  
> &nbsp;&nbsp;&nbsp;&nbsp;block:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Set status omit host  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OOC\_status: false

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Asset that it is authorized  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "'Status: AUTHORIZED' in license3.stdout[0]"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fail\_msg: "Device is not Authorized"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success\_msg: "Device Authorized"  
> &nbsp;&nbsp;&nbsp;&nbsp;rescue:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Set status add host  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OOC\_status: true

&nbsp;&nbsp;&nbsp;&nbsp;- name: Add devices to the OOC list  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OOC: "{{ hostvars|dict2items|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;json\_query('[?value.OOC\_status].key') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run\_once: true

&nbsp;&nbsp;&nbsp;&nbsp;- name: Send a team message ...

---

<div class="post-metadata">

**Author:** ![Jason](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jason/32/304_2.png) [@Jason](https://forum.ansible.com/u/Jason)\
**Post date:** [October 24, 2020, 4:48pm UTC](https://forum.ansible.com/t/create-a-list-of-failed-tasks/34095/3 "2020-10-24T16:48:57Z")

</div>

Worked - Just had to add {{ OOC | join(', ') }} to clean up the output. Thank you Vladimir.
