In this playbook:
- hosts: all
tasks:
- name: task A
debug: msg="task A"
tags:
- A
- name: task B
debug: msg="task B"
tags:
- B
- name: untagged task
debug: msg="untagged task"
I would like to run the task with the tag A and the untagged task.
I know about the --skip-tags option, but this a simplified example.
My use case is for a very complex playbook with many tags and roles with tasks with different tags, and interdependencies between tagged and non-tagged tasks. Long story short, the only 'clean' option for me is to run only specified tags and those untagged.
Is there a way to call ansible-playbook so that it'll run specific tags and untagged tasks only?
I'm using ansible 2.9.6
This is possible, indeed:
For example, if you wanted to just run the “configuration” and “packages” part of a very long playbook, you can use the --tags option on the command line:
ansible-playbook example.yml --tags "configuration,packages"
Source: https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#tags
Along with:
There are another 3 special keywords for tags:
tagged,untaggedandall, which run only tagged, only untagged and all tasks respectively.
Source: https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#special-tags
So your solution is:
ansible-playbook --tags "untagged,A" playbook.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With