Can 'template' result be registered?

Should something like the following work?

  • name: update file from templated
    template: src=config.j2 dest=/etc/config
    register: result

  • name: run command if /etc/config changed
    command: /usr/bin/command -option arg
    when: result|changed

When I run the first task and the content of ‘/etc/config’ changes I get a changed status for the task. I the content of the file doesn’t change I get an ok status. So I would expect the above to work but it doesn’t, I simply get a Conditional expression must evaluate to True or False… fatal error.

Can someone clarify if it is by design that template module results can’t be registered? Is there a workaround for what I’m trying to achieve?

Thanks.

All you need to do is “when: result.changed”.

You’re absolutely right James. I had actually already used this in another playbook but for some reason was getting confused. Thanks!
–Pedro.

We really should make a “|changed” like “|failure” and “|success” so that this works.

The only difference is the filter understands lists when there is not a top level .changed element.