only_if last_result.changed

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]

____________________________________________________
< TASK: [If we added the banner config restart SSHd] >
----------------------------------------------------
        \ :slight_smile:
         \ (oo)\_______
            (__)\ )\/\
                >>----w |
                >> >>

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

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

Even better!

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

ok trying! thanks guys.

james