Ansible:在剧本中,按标签过滤角色,而无需在命令行中传递 [英] Ansible: In a playbook, filter a role by tag(s) without passing at the command-line
问题描述
在Ansible 1.7中,我可以从命令行使用--tags仅运行该剧本任务的一个子集.
In Ansible 1.7, I can use --tags from the command-line to only run a subset of that playbooks tasks.
但是我想融入我的剧本中,以仅与标签匹配的任务来运行一组角色.也就是说,我不想通过命令行将其传递进来,因为每次都相同.
But I'm wanting to bake into my playbook to run a set of roles with only tasks that match tags. That is, I don't want to have to pass this in via the command-line since it will be the same every time.
起初我以为是这个命令,但这却相反:用这些标记标记任务,而不是根据这些标记将它们过滤掉.
At first I thought it was this command, but this does the opposite: tagging tasks with these tags instead of filtering them out based on this.
roles:
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
我可以想象使用条件语句来实现这一点,但是标签将是实现这一目标的一种更为优雅的方式.
I can imagine implementing this using conditionals but tags would be a much more elegant way of achieving this.
推荐答案
当前版本的Ansible只有以下选项:
You only have the following options with the current version of Ansible:
- 在命令行上指定标签
- 使用变量而不是标签来有条件地运行任务
- 将您的网络服务器角色拆分为多个角色,并将角色依赖性用于常见任务
此功能请求已多次出现在邮件列表中而且我还没有看到开发团队的任何迹象表明它将被添加为一项新功能.
This feature request has come up on the mailing list a few times and I haven't seen any indication from the dev team that it will be added as a new feature.
这篇关于Ansible:在剧本中,按标签过滤角色,而无需在命令行中传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!