gpt4 book ai didi

ansible - 如何使用 Ansible Playbook 与特定组一起玩

转载 作者:行者123 更新时间:2023-12-02 16:48:07 25 4
gpt4 key购买 nike

Ansible版本:2.1.0

我的 ansible 主机文件是:

[PM]
xyz.example.com ansible_connection=ssh

[ND]
pqr.example.com ansible_connection=ssh

[CM]
xyz.example.com ansible_connection=ssh
pqr.example.com ansible_connection=ssh

剧本是:

- hosts: PM:ND:CM
remote_user: root
tasks:
{some thing}

- hosts: PM
remote_user: root
tasks:
{some thing}

- hosts: ND
remote_user: root
tasks:
{some thing}

- hosts: CM
remote_user: root
tasks:
{some thing}

我正在使用以下命令运行 playbook:

ansible-playbook --limit 'PM' akana-installation.yml

但是剧本仍然在所有主机上运行,​​这意味着

Play 'PM:ND:CM'
Play 'PM'
Play 'ND'
Play 'CM'

所有戏剧都在播放。请帮我解决这个问题。

我需要的是:在执行剧本时,我将给出组名称,只有组才能玩,所以请让我知道是否还有其他方法。

最佳答案

最初的问题是:--限制选项不起作用

通过调用 ansible-playbook --limit 'PM' akana-installation.yml,您可以告诉 ansible 将服务器限制为 PM 组中的主机。
在您的情况下,它将是 xyz.example.com
请记住,如果您将此服务器放在多个组中(就像您所做的那样),它仍然是这些组的成员。
您的有限库存将变为:

[PM]
xyz.example.com ansible_connection=ssh

[ND]

[CM]
xyz.example.com ansible_connection=ssh

ansible-playbook 将执行 playbook 中适用于 xyz.example.com 的每个 play。
对于您的情况:

Play 'PM:ND:CM'
[xyz.example.com]
Play 'PM'
[xyz.example.com]
Play 'ND'
skipping: no hosts matched
Play 'CM'
[xyz.example.com]

关于ansible - 如何使用 Ansible Playbook 与特定组一起玩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324714/

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