# use command output to trigger a new task

**URL:** <https://forum.ansible.com/t/use-command-output-to-trigger-a-new-task/20933>\
**Category:** Ansible Project\
**Created:** [March 20, 2016, 1:42pm UTC](https://forum.ansible.com/t/use-command-output-to-trigger-a-new-task/20933 "2016-03-20T13:42:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Zoltan\_Kereszt](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Peter\_Zoltan\_Kereszt](https://forum.ansible.com/u/Peter_Zoltan_Kereszt)\
**Post date:** [March 20, 2016, 1:42pm UTC](https://forum.ansible.com/t/use-command-output-to-trigger-a-new-task/20933/1 "2016-03-20T13:42:59Z")

</div>

Hello,

I am trying to remove unused kernel packages when the command output is larger than 1

the tasks looks like this:

- name: Check if kernel upgrade is available

command: dpkg -l linux-image\* | grep ii | wc -l 2\>&1

register: kernelinstalled

- name: Delete unused linux kernels

command: apt-get remove $(dpkg -l linux-image\* | grep ii | grep -v $(uname -r) | awk ‘{print $2}’)

when: kernelinstalled.stdout \>= 2

however when I run a check of the playbook I get the following failure:

TASK [nginx : Delete unused linux kernels] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [10.160.125.74]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘kernelinstalled.stdout \>= 2’ failed. The error was: error while evaluating conditional (kernelinstalled.stdout \>= 2): ‘dict object’ has no attribute ‘stdout’\n\nThe error appears to have been in ‘/etc/ansible/roles/nginx/tasks/main.yml’: line 20, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#\n- name: Delete unused linux kernels\n ^ here\n”}

Any idea how can I make that work?

Regards,

Peter

---

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 21, 2016, 10:30am UTC](https://forum.ansible.com/t/use-command-output-to-trigger-a-new-task/20933/2 "2016-03-21T10:30:27Z")

</div>

Have you run it in debug to see what the kernalinstalled object looks like?

- debug: var=kernalinstalled

Also, I do believe the 2 needs to be like ‘2’ as its actually a string not a integer thats returned. I think if you do something like kernalinstalled.stdout|int \> 2 that may also work as well.
