Ansible 调试模块:无论主机数量如何,仅显示一次调试消息

问题描述 投票:0回答:1

我想在我的剧本中显示调试消息。

这是我的剧本:

[blablabla]
- debug:
    msg:
    - "######################################################################"
    - "                    DIAGNOSTIC AGENT INSTALLATION                     "
    - "######################################################################"
[blablabla]

当我在多个目标上运行此剧本时,控制台输出上的调试消息显示的次数与主机计数相同(按预期)。

TASK [sifac-sap-diagnosticagent : debug] *******
task path: /etc/ansible/xxxxxx/tasks/main.yml:158
ok: [server1] => {
    "msg": [
        "######################################################################",
        "                    DIAGNOSTIC AGENT INSTALLATION                     ",
        "######################################################################"
    ]
}
ok: [server2] => {
    "msg": [
        "######################################################################",
        "                    DIAGNOSTIC AGENT INSTALLATION                     ",
        "######################################################################"
    ]
}
ok: [server3] => {
    "msg": [
        "######################################################################",
        "                    DIAGNOSTIC AGENT INSTALLATION                     ",
        "######################################################################"
    ]
}
ok: [server4] => {
    "msg": [
        "######################################################################",
        "                    DIAGNOSTIC AGENT INSTALLATION                     ",
        "######################################################################"
    ]
}

无论主机数量如何,我只想显示此消息一次。这是为了不让我的输出超载。

我应该使用调试ansible模块中的选项bypass_host_loop吗?还有其他方法吗?

enter image description here

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html

ansible ansible-2.x ansible-module
1个回答
0
投票

在任务上使用 run_once 关键字。它将仅为第一个可用主机运行任务。

另请在 playbook 关键字中查找 run_once

[blablabla]
- debug:
  msg:
    - "######################################################################"
    - "                    DIAGNOSTIC AGENT INSTALLATION                     "
    - "######################################################################"
  run_once: true
[blablabla]
© www.soinside.com 2019 - 2024. All rights reserved.