本文介绍了按区域运行 Ansible Playbook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


首先:我仍然是一个 Ansible 新手,我只是习惯了它.


first of all: I am still an Ansible newbie and I am just getting used to it.

我想编写一个剧本,根据客户端的位置调用不同的剧本.

i want to write a playbook that calls up a different playbook depending on the location of the client.

例如:
我有 3 个不同的剧本专门针对某些地区,usaclient.yml、euclient.yml 和 asiaclient.yml

For example:
i have 3 different playbooks specifically for certain regions, usaclient.yml, euclient.yml and asiaclient.yml

这些剧本应该通过主剧本"自动执行.

these playbooks should be executed automatically via a "master playbook".

如果在欧洲客户端上执行主剧本",则应启动剧本euclient.yml".

if the "master playbook" is executed on a european client, the playbook "euclient.yml" should be started.

有谁知道如何将剧本自动分配给一个区域或知道如何通过 bash 脚本解决这个问题?

does anyone know how to assign playbooks automatically to a region or has an idea how to solve this by bash script?

最好的问候
D1Ck3n

best regards
D1Ck3n

推荐答案

Q: "如果在欧洲客户端上执行主剧本",剧本 euclient.yml 应该是开始了."

Q: "If the "master playbook" is executed on a European client, the playbook euclient.yml should be started."

A:在 Ansible 中,不可能有条件地启动剧本.请参阅import_playbook.

A: In Ansible it's not possible to start a playbook conditionally. See import_playbook.

只有 2 个选项.通过外部工具有条件地启动剧本或测试剧本内部的条件.尝试 ansible-runner.

There are 2 options only. Start the playbook conditionally by an external tool or test the condition inside the playbook. Try ansible-runner.

这篇关于按区域运行 Ansible Playbook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 18:06