error on change notify

40 views
Skip to first unread message

Mark Olliver

unread,
Sep 9, 2014, 2:35:53 PM9/9/14
to ansible-project
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


--
MARK OLLIVER
HEAD OF IT OPERATIONS
 
T. +44(0) 20 7775 5628
 
Infectious Media
3-7 Herbal Hill / London / EC1R 5EJ
www.infectiousmedia.com
 
Infectious Media 
FacebookTwitterLinkedInYoutube 
 
 
 
This email and any attachments are confidential and may also be
privileged. If you are not the intended recipient, please notify the sender
immediately, and do not disclose the contents to another person, use it for
any purpose, or store, or copy the information in any medium. Please also
destroy and delete the message from your computer.
 


Scott Sturdivant

unread,
Sep 9, 2014, 3:18:55 PM9/9/14
to ansible...@googlegroups.com
You want "when: restart_supervisor|changed".  See:  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

--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CALKPxXi1BrFU-AZnEsnBVifLjpJL_VjYuKmhdPk-nwwD3OJHmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Sep 9, 2014, 3:20:41 PM9/9/14
to ansible...@googlegroups.com
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:


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.



Michael DeHaan

unread,
Sep 9, 2014, 3:22:38 PM9/9/14
to ansible...@googlegroups.com
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.





Mark Olliver

unread,
Sep 9, 2014, 3:30:52 PM9/9/14
to ansible-project

Hi

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

Thanks

Mark

Mark Olliver
Head of IT Operations
InfectiousMedia

Reply all
Reply to author
Forward
0 new messages