handler + include

106 views
Skip to first unread message

ProfHase

unread,
Oct 8, 2014, 6:48:54 AM10/8/14
to ansible...@googlegroups.com
Hi,

having the following task in my main.yml in a role (tasks/main.yml):

- name: mytask
  copy
:
    src
=/source
    dest=/
destination
  notify
: redeploy


with the following handler ( handlers/main.yml):

- name: redeploy
  include
: redeploy.yml

I am getting:

ERROR: change handler (redeploy) is not defined

Is this behaviour intended?

I thought of this as the most concise way to consolidate multiple handler tasks.
(I know, there was already a mail  here with the suggestion to notify other handlers in handler which does not seem semantically appropriate)

Michael DeHaan

unread,
Oct 8, 2014, 8:41:07 AM10/8/14
to ansible...@googlegroups.com
What's defined in handlers/redeploy.yml?



--
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/a4a328d3-52a9-4d9d-aaff-dfe270db9ce9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ProfHase

unread,
Oct 8, 2014, 8:48:29 AM10/8/14
to ansible...@googlegroups.com
In the handlers/redeploy.yml there are several tasks:

- name: copy installation files
  copy
:
   
...

- name: run install script
  command
:
   
...

- name: restart myservice
  service
:
   
...



Michael DeHaan

unread,
Oct 8, 2014, 8:50:18 AM10/8/14
to ansible...@googlegroups.com
Yeah, handlers don't work like that, with a "name" on the include like that.

Each handler must have a name and you must notify the names of the handlers specifically.




--
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.

ProfHase

unread,
Oct 8, 2014, 9:17:52 AM10/8/14
to ansible...@googlegroups.com
Would that be a possible feature request?
It seems quite logical to me that (like in my case) a handler could consist of multiple related tasks.

Or do I oversee anything?

David Karban

unread,
Oct 12, 2014, 4:30:40 AM10/12/14
to ansible...@googlegroups.com
Hi,

you can call more, than one handler:
- name: mytask
  copy
:
    src
=/source
    dest=/
destination
  notify
:

    - copy installation files
    - run install script
    - restart myservice

David


--
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.

ProfHase

unread,
Nov 18, 2014, 7:24:16 AM11/18/14
to ansible...@googlegroups.com
Thanks, that is the way I did it. I just think that logically those three (in my case those are 7) operations are just one handler.
(To explain that: if one file has changed, the whole application needs to be rebuilt)
So none of the 7 handlers will ever be called alone and it would require less copy-paste (as the application needs to be rebuilt on change of multiple files)

Toshio Kuratomi

unread,
Nov 18, 2014, 3:48:47 PM11/18/14
to ansible...@googlegroups.com
On Tue, Nov 18, 2014 at 4:24 AM, ProfHase <profh...@gmail.com> wrote:
> Thanks, that is the way I did it. I just think that logically those three
> (in my case those are 7) operations are just one handler.
> (To explain that: if one file has changed, the whole application needs to be
> rebuilt)
> So none of the 7 handlers will ever be called alone and it would require
> less copy-paste (as the application needs to be rebuilt on change of
> multiple files)
>
This does make sense logically. However, since it's possible to
invoke all the handler tasks in a fairly straightforward way this
would probably be fairly low priority. Perhaps in the future the v2
refactoring will make it easier for us to look into making this
change. At the moment we're just not in a good position to see this
implemented now.

-Toshio
Reply all
Reply to author
Forward
0 new messages