0

我有4本剧本。其中 2 个正在我的目标计算机上部署服务,其中 2 个正在再次删除它们。现在我想把它们放在角色中。但我不确定最佳实践是什么。
2 个部署剧本只是使用不同的变量和模板做完全相同的事情。同样适用于删除剧本。

Atm 我的结构如下所示:

ansible.cfg
ssh_key
inventoryfile
group_vars
    ....
roles
    deployservicegroupA
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           copy-service-templates.yml
           start-services.yml
    deployservicegroupB
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           copy-service-templates.yml
           start-services.yml
    removeservicegroupA
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           remove-services.yml
           cleanup.yml
    removeservicegroupB
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           remove-services.yml
           cleanup.yml

这是他们打算由用户完成的方式吗?
我特别想知道我的任务做完全相同的事情,但可以在不同的角色中找到。如果我应该将我的任务包含在 main.yml 任务文件中。

4

1 回答 1

2

根据您的评论,您为每个服务使用一个组,您可以使用 group_vars 指定要使用的变量。

然后您可以将角色合并在一起,您唯一需要做的就是根据您正在运行游戏的组加载特定模板。

于 2016-04-14T14:47:00.637 回答