gpt4 book ai didi

ansible - 如何仅根据条件通知 Ansible 中的处理程序?

转载 作者:行者123 更新时间:2023-12-04 12:05:46 25 4
gpt4 key购买 nike

我想通过执行以下操作来通知我角色中的处理程序:

- name: Notify handler
notify: my_handler
when: this_thing_is_true|bool

但 Ansible 只是提示:

ERROR! no module/action detected in task.



我尝试过各种楔子,例如:

- name: Notify handler
meta: noop
notify: my_handler
when: this_thing_is_true|bool

但同样的提示:

[WARNING]: noop task does not support when conditional Any suggestions?

最佳答案

请注意,运行任务不足以通知处理程序,您还需要一个创建更改结果的任务。

changed_when 的帮助下,您可以在任何任务上获得更改结果。 Ansible 中的选项。
然后,做一个简单的 debug 可能是一个选择。

我的其他想法,但最终没有真正意义:

  • pause :但您不能暂停少于一秒
  • assert :但是断言您还需要放入 changed_that 的相同条件感觉很愚蠢通知处理程序。您仍然可以assert: that: true但感觉同样愚蠢。
  • 也许我能想到的最愚蠢的想法是 fail带有 failed_when: false 的任务.
  • command: 'true'与上述相比,可能不那么愚蠢,但我并不完全相信,仍然

  • 鉴于剧本:

    - hosts: local
    gather_facts: no
    vars:
    this_thing_is_true: true

    tasks:
    - debug:
    msg: 'Notifying handlers'
    # var: this_thing_is_true
    # ^-- might be an alternative option to msg:
    changed_when: this_thing_is_true
    notify:
    - me

    handlers:
    - name: me
    debug:
    msg: 'I have been notified'

    回顾一下:
    PLAY [local] *******************************************************************

    TASK [debug] *******************************************************************
    changed: [local] => {
    "msg": "Notifying handlers"
    }

    RUNNING HANDLER [me] ***********************************************************
    ok: [local] => {
    "msg": "I have been notified"
    }

    PLAY RECAP *********************************************************************
    local : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

    关于ansible - 如何仅根据条件通知 Ansible 中的处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62182998/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com