【问题标题】:Ansible - how to use include_role in handlerAnsible - 如何在处理程序中使用 include_role
【发布时间】:2017-11-23 23:23:38
【问题描述】:

鉴于以下剧本,在处理程序中调用具有虚拟角色 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'

【问题讨论】:

    标签: ansible


    【解决方案1】:

    您所描述的问题目前在 Ansible git 存储库中似乎有一个与之相关的未解决问题:include_role doesn't work from handlers

    目前:

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

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 2023-02-21
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多