On Monday, December 22, 2014 2:07:36 PM UTC-5, Dimitri Yioulos wrote:
>
> Hi, all.
>
> I'm an Ansible newbie trying to create a playbook which will: 1) update
> all packages on a CentOS 6 box via yum, and 2) reboot the server if the
> kernel has been updated. Here's my palybook:
>
> ---
>
> - hosts: all
> tasks:
> - name: yum update
> yum: name=* state=latest
>
> - name: Check for reboot hint.
> shell: if [ `rpm -qa --last|grep kernel-2.6| cut -d'-' -f2- | awk
> '{print $1}' | head -n 1` != `uname -r` ]; then echo "reboot"; else echo
> "no"; fi
> ignore_errors: true
> register: reboot_hint
> - name: Rebooting ...
> command: shutdown -r now "Yum kernel update applied"
> when: reboot_hint.stdout.find('reboot') == 'reboot'
> async: 0
> poll: 0
> ignore_errors: true
> register: rebooting
>
> (the last "register" is meaningless for the time being)
>
> The "Check for reboot hint" works, as tested against machines requiring a
> reboot and those not, via a test bash script. However, no matter wheat I
> put in my "when" conditional in the playbook, it fails with "error while
> evaluating conditional".
>
> Help would be greatly appreciated.
>
> Dimitri
>
With some help from IRC channel, the fix was really simple. And, I was
able to streamline, too. Here's the working copy of my playbook:
---
- hosts: all
tasks:
- name: yum update
yum: name=* state=latest
- name: Check for reboot hint.
shell: if [ `rpm -qa --last|grep kernel-2.6| cut -d'-' -f2- | awk
'{print $1}' | head -n 1` != `uname -r` ]; then echo "reboot"; else echo
"no"; fi
register: reboot_hint
always_run: yes
- name: Rebooting ...
command: shutdown -r now "Yum kernel update applied"
when: reboot_hint.stdout.find('reboot') != -1
register: rebooting
--
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/3db7a037-4a9a-4360-a653-3e660a217c66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.