Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives for flush_handlers in ansible

I have handlers in my Ansible playbook and I want to trigger these notifies immediately. How can this be achieved without calling the meta_handler = flush_handler? This works fine in Ansible 2.5.6 but after this version there is a warning displayed saying:

[WARNING]: flush_handlers task does not support when conditional

Any help would be appreciated.

like image 369
ravi Avatar asked Oct 16 '22 10:10

ravi


1 Answers

It's an open issue meta: flush_handlers doesn't honor when clause #41313.

(2021-04-20 the issue is still open. Please comment here if status changes)

Quoting my comment:

Let me describe a valid scenario (below). "flush_hadlers" is needed after tasks abc.yml complete and before tasks def.yml start. But the file with the tasks xyz.yml is imported when OS is RH only. Here Ansible complains:

[WARNING]: flush_handlers task does not support when conditional

It would be nice to be able to suppress the warning.

# cat xyz.yml
- include_tasks: abc.yml
- meta: flush_handlers
- include_tasks: def.yml

# cat playbook.yml
  ...
  tasks:
    - import_tasks: xyz.yml
      when: (ansible_os_family == "RedHat" )
like image 70
Vladimir Botka Avatar answered Oct 23 '22 21:10

Vladimir Botka