Ansible - 如何在处理程序中使用 include_role

use*_*547 3 ansible

foo鉴于以下剧本,在处理程序中使用虚拟角色调用 include_role 不起作用。根据文档

处理程序是任务列表,与常规任务没有任何区别,它们由全局唯一名称引用,并由通知程序通知。

include_role但是,在使用(和 Ansible 2.4.1)时它似乎不起作用。是否有任何解决方法或其他语法可以使其运行?

- name: test roles
  hosts: localhost
  gather_facts: false

  tasks:

  - debug:
      msg: "call handler"
    changed_when: true
    notify: "bar"

  handlers:

   - name: "bar handler"
     include_role:
       name: foo
     listen: "bar"
Run Code Online (Sandbox Code Playgroud)

输出:

[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
[WARNING]: Ignoring invalid attribute: listen


PLAYBOOK: playbook.yml *****************************************************************************
1 plays in playbook.yml

PLAY [test roles] *****************************************************************************
ERROR! Unexpected Exception, this is probably a bug: 'IncludeRole' object has no attribute 'listen'
Run Code Online (Sandbox Code Playgroud)

Pic*_*Cls 6

看起来您所描述的问题当前在 Ansible git 存储库上有一个与之相关的未解决问题:include_role 无法从处理程序中工作

眼下:

当在处理程序中使用 include_role 模块时,调用角色会在知道是否会调用处理程序之前失败。