# only\_if last\_result.changed

**URL:** <https://forum.ansible.com/t/only-if-last-result-changed/12316>\
**Category:** Ansible Project\
**Created:** [February 8, 2013, 7:22pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316 "2013-02-08T19:22:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![James8](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@James8](https://forum.ansible.com/u/James8)\
**Post date:** [February 8, 2013, 7:22pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316/1 "2013-02-08T19:22:24Z")

</div>

Hi,  
Am I doing this wrong? I’m not sure if I’m doing the only\_if correctly?

- name: copy a better SSH Config  
action: copy src=…/…/…/global/templates/sshd\_config.j2 dest=/etc/ssh/sshd\_config owner=root group=root mode=0644  
tags:

- ConfigureSSH

- name: Copy Security Banner  
action: copy src=…/…/…/global/files/banner dest=/etc/banner owner=root group=root mode=0644  
tags:

- ConfigureSSH

- DeployBanner

- name: Check to see if the sshd config has the banner config and add it if it doesn’t  
action: lineinfile dest=/etc/ssh/sshd\_config regexp=“Banner /etc/banner” line=“Banner /etc/banner” insertafter=EOF state=present backup=yes  
tags:

- ConfigureSSH

- DeployBanner

- name: If we added the banner config restart SSHd  
action: service name=sshd state=restarted  
only\_if: ‘${last\_result.changed}’  
tags:

- ConfigureSSH

- DeployBanner

ok: [[ws023.frolickinglama.com](http://ws023.frolickinglama.com)]

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 8, 2013, 7:32pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316/2 "2013-02-08T19:32:27Z")

</div>

> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> \< TASK: [If we added the banner config restart SSHd] \>  
> ----------------------------------------------------  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ 🙂  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ (oo)\_\_\_\_\_\_\_  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(\_\_)\ )\/\  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>\>----w |  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>\> \>\>
> 
> fatal: [ws023.frolickinglama.com] =\> Could not evaluate the expression:  
> ${last\_result.changed}

$last\_result is no longer automatically registered in Ansible

so it looks like you just need to do a

register: $last\_result

on the task

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [February 8, 2013, 7:36pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316/3 "2013-02-08T19:36:15Z")

</div>

Also you might want to change the restart into a handler, then you  
don't have to deal with variables

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 8, 2013, 7:38pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316/4 "2013-02-08T19:38:39Z")

</div>

Even better!

If we allow immediate\_notify in the future, the "last result changed"  
pattern is going to be completely unnecessary then too.

---

<div class="post-metadata">

**Author:** ![James8](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@James8](https://forum.ansible.com/u/James8)\
**Post date:** [February 8, 2013, 7:44pm UTC](https://forum.ansible.com/t/only-if-last-result-changed/12316/5 "2013-02-08T19:44:54Z")

</div>

ok trying! thanks guys.

james
