last task

Hi,

I am writing a role to setup ‘things’ on amazon ami (redhat based I suppose).

I have a yum upgrade step on it like so:

  • name: upgrade all base packages
    yum: name=* state=latest

then ‘other stuff gets done’ like installing some additional software.

I want to put this next step in place to check if kernel version has changed or not and if so, reboot the server.

  • name: Check what the new version is
    shell: lsb_release -r | awk ‘{print $2}’
    register: new_release

  • name: Reboot
    command: /sbin/reboot -t now
    when: {{ amzn_base_lsb_release }} != new_release.stdout

amzn_base_lsb_release = defined in defaults/main.yml

Q: Is there a way for me to define this as the last step?
(this is a role and this task in defined in tasks/RedHat.yml inherited by tasks/main.yml)

Thanks in advance!

Yes, I’m going to release this as soon as it gets right (well, its my first role) :slight_smile:

Cheers,
Frank

“Q: Is there a way for me to define this as the last step?”

Ansible is order based, so if you want a task to go last, make it the very last task in the last play in your playbook, and flush the handlers before running it

  • meta: flush_handlers
  • shell: echo “I am the last task”

This may it will make sure any other handlers complete before running the task.