【问题标题】:Triggering a handler from a role once从角色触发处理程序一次
【发布时间】:2015-12-02 20:11:45
【问题描述】:

我已定义所有库存和角色。其中一个角色负责数据库状态,并具有一个处理程序,该处理程序在角色中的任务接触数据库时触发清理。

现在我需要按需清理所有数据库节点上的数据库,我自然想使用已经知道该怎么做的处理程序。

我已经为它创建了一个剧本,导入了所需的角色,但是,看起来我不能只通知处理程序。

   - hosts: db_updaters
     roles:
       - db_updater
     tasks:
       - name: Run DB cleanup
         notify: Cleanup DB

当我执行那个剧本时,我得到了

ERROR: 'action' or 'local_action' attribute missing in task "Run DB cleanup"

【问题讨论】:

    标签: ansible ansible-playbook


    【解决方案1】:

    你可以这样做:

    - name: notify handler
      debug: msg="notify handler"
      notify: Cleanup DB
    

    如果这不起作用,那么应该这样做:

    - name: notify handler
      command: /bin/true
      notify: Cleanup DB
    

    【讨论】:

    • 我以前使用过/bin/true 变体。添加delegate_to: localhost 可以稍微提高速度。
    猜你喜欢
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    相关资源
    最近更新 更多