# error on change notify

**URL:** <https://forum.ansible.com/t/error-on-change-notify/16162>\
**Category:** Ansible Project\
**Created:** [September 9, 2014, 6:35pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162 "2014-09-09T18:35:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Olliver](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mark\_Olliver](https://forum.ansible.com/u/Mark_Olliver)\
**Post date:** [September 9, 2014, 6:35pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162/1 "2014-09-09T18:35:45Z")

</div>

Hi,

I am getting the following error one the second run of my play book but i am not sure why or what I should be doing to correct it.

fatal: [idb-13] =\> error while evaluating conditional: {u’changed’: False, u’group’: u’root’, u’uid’: 0, ‘dest’: u’/usr/local/bin/im\_supervisor’, ‘md5sum’: ‘a5d74c539224f1c7a3dfdf091af13c64’, u’owner’: u’root’, u’state’: u’file’, u’gid’: 0, u’mode’: u’0700’, ‘invocation’: {‘module\_name’: u’copy’, ‘module\_args’: u’src=im\_supervisor dest=/usr/local/bin/im\_supervisor mode=0700’}, u’path’: u’/usr/local/bin/im\_supervisor’, u’size’: 239}

Here is the relevant part of the common/tasks/main.yml

- name: configure supervisor  
copy: src=supervisord.conf dest=/etc/supervisor/supervisord.conf  
register: restart\_supervisor

- name: configure supervisor default  
copy: src=supervisor.default dest=/etc/default/supervisor  
register: restart\_supervisor

- copy: src=im\_supervisor dest=/usr/local/bin/im\_supervisor mode=0700  
register: restart\_supervisor

- shell: /usr/local/bin/im\_supervisor restart;  
when: restart\_supervisor

Thanks

Mark

---

<div class="post-metadata">

**Author:** ![Scott\_Sturdivant](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Scott\_Sturdivant](https://forum.ansible.com/u/Scott_Sturdivant)\
**Post date:** [September 9, 2014, 7:18pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162/2 "2014-09-09T19:18:45Z")

</div>

You want “when: restart\_supervisor|changed”. See: [http://docs.ansible.com/playbooks\_variables.html#filters-often-used-with-conditionals](http://docs.ansible.com/playbooks_variables.html#filters-often-used-with-conditionals)

However, by registering the variable each time, you’re not going to get the behavior you’re after. If the first task changes, but the second two do not, I don’t believe that you’ll restart supervisor. Instead, look into handlers: [http://docs.ansible.com/playbooks\_intro.html#handlers-running-operations-on-change](http://docs.ansible.com/playbooks_intro.html#handlers-running-operations-on-change)

---

<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:** [September 9, 2014, 7:20pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162/3 "2014-09-09T19:20:36Z")

</div>

Hi Mark,

It looks like you’re not quite up to speed on how conditionals work yet, and that’s ok.

What you have registered in the first call is the result of the operation, which is a hash (or a dictionary, as Python calls it).

Each time you are then storing a _different_ result in it, as you have it written, each time a different hash.

At no point is this hash table actually a boolean, which is why you can’t just use it there in the conditional.

It sounds like you are trying to restart supervisor only if any of the above 3 things changed, which _CAN_ be done the way you have it, but you would need to set three different vars and then do:

when: foo.changed or bar.changed and baz.changed

But that’s a hack.

A much better thing to do would be to use handlers:

[http://docs.ansible.com/playbooks\_intro.html](http://docs.ansible.com/playbooks_intro.html)

Signalled here by “notify”.

If you need handlers to run at a certain point, rather than the end of the play, you can use the task:

- meta: flush\_handlers.

---

<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:** [September 9, 2014, 7:22pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162/4 "2014-09-09T19:22:34Z")

</div>

For completeness:

- name: configure supervisor  
copy: src=supervisord.conf dest=/etc/supervisor/supervisord.conf  
notify: restart supervisor

- name: configure supervisor defaults  
copy: src=supervisor.default dest=/etc/default/supervisor  
notify: restart supervisor

- name: copy over file  
copy: src=im\_supervisor dest=/usr/local/bin/im\_supervisor mode=0700  
notify: restart supervisor

- meta: flush\_handlers # only if you want to do this now and not at the end of the play

In your handlers file:

- name: restart supervisor  
shell: …

There are also supervisor modules in ansible that you can use, or the service module.

---

<div class="post-metadata">

**Author:** ![Mark\_Olliver](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mark\_Olliver](https://forum.ansible.com/u/Mark_Olliver)\
**Post date:** [September 9, 2014, 7:30pm UTC](https://forum.ansible.com/t/error-on-change-notify/16162/5 "2014-09-09T19:30:33Z")

</div>

Hi

Thanks yep I think I got notify and register a bit mixed up

Thanks

Mark

Mark Olliver  
Head of IT Operations  
InfectiousMedia
