limiting handlers scope

Hi,

I have multiple roles and playbooks (consisting of roles). Almost every role starts with repository configuration. After repos configuration, repo database must be updated. My current solution looks like this:

base_role:

  • name: set percona src list
    template: src=percona.list dest=/etc/apt/sources.list.d force=yes backup=yes
    tags: repos
  • name: update apt cache
    apt: update_cache=yes
    tags: repos

    some_roles_with_apt_updates

    host_specific_role:
  • name: set host_specific src list
  • name: update apt cache

So, I have many unnecessary apt cache updates while testing the playbook. Obvious solution is to use handlers, which will not be triggered if apt source files was not changed. For now, I can’t move repo db update action to handlers, because handlers will run after all tasks, thus, the database will be updated after the packages installation (which will fall due to the non-upgraded database =).

What is the right way to implement such workflow (update repo db right now, but only if repos was changed)? May be roles dependency feature can help me - is there some sort of handlers, which limited only to current role? Or may be I should just wait while repo cache will be upgraded =)

If you look at the apt module docs there are parameters to decide how often the cache is updated.

You can use these at the same time as the update call.

I’m not sure why you need handlers that are unique to the current role – can you share more information? I don’t see any notifies in what was pasted above so having some difficulty following the question.

Thanks!