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

时间:2017-11-23 13:54:51

标签: ansible

鉴于以下playbook,在处理程序中调用带有伪角色foo的include_role是行不通的。 According to the doc

  

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

但是,使用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"

输出:

[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'

1 个答案:

答案 0 :(得分:2)

看起来您正在描述的问题目前在Ansible git存储库上有一个与之相关的未解决问题:include_role doesn't work from handlers

目前:

  

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