Can 'template' result be registered?

2,181 views
Skip to first unread message

Pedro Romano

unread,
Aug 14, 2013, 11:55:29 AM8/14/13
to ansible...@googlegroups.com
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.

James Cammarata

unread,
Aug 14, 2013, 11:59:33 AM8/14/13
to ansible...@googlegroups.com
On Wed, Aug 14, 2013 at 10:55 AM, Pedro Romano <pmc...@gmail.com> wrote:
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

All you need to do is "when: result.changed".


--

James Cammarata <jcamm...@ansibleworks.com>
Sr. Software Engineer, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Pedro Romano

unread,
Aug 14, 2013, 12:54:19 PM8/14/13
to ansible...@googlegroups.com
You're absolutely right James. I had actually already used this in another playbook but for some reason was getting confused. Thanks!
--Pedro.

Michael DeHaan

unread,
Aug 14, 2013, 1:49:26 PM8/14/13
to ansible...@googlegroups.com
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.






On Wed, Aug 14, 2013 at 12:54 PM, Pedro Romano <pmc...@gmail.com> wrote:
You're absolutely right James. I had actually already used this in another playbook but for some reason was getting confused. Thanks!
--Pedro.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Reply all
Reply to author
Forward
0 new messages