# last task

**URL:** <https://forum.ansible.com/t/last-task/16000>\
**Category:** Ansible Project\
**Created:** [August 21, 2014, 5:26pm UTC](https://forum.ansible.com/t/last-task/16000 "2014-08-21T17:26:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank3](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@Frank3](https://forum.ansible.com/u/Frank3)\
**Post date:** [August 21, 2014, 5:26pm UTC](https://forum.ansible.com/t/last-task/16000/1 "2014-08-21T17:26:23Z")

</div>

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) 🙂

Cheers,  
Frank

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 22, 2014, 12:09pm UTC](https://forum.ansible.com/t/last-task/16000/2 "2014-08-22T12:09:51Z")

</div>

“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.
