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.
On Monday, 21 March 2016 05:37:22 UTC+11, Peter Zoltan Keresztes wrote:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/263e865d-e1d3-4421-966a-7806372f02e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.