问题
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.
回答1:
You only have the following options with the current version of Ansible:
- Specify the tags on the command line
- Use a variable instead of a tag to conditionally run tasks
- Split your webserver role into multiple roles and use role dependencies for the common tasks
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.
回答2:
The use of conditionals can meet your needs.
You can see more information in my answer to another person's similar question here.
来源:https://stackoverflow.com/questions/25674649/ansible-in-a-playbook-filter-a-role-by-tags-without-passing-at-the-command-l