Is it possible to set tags
per each item in a with_item
statement?
Assume I have a task:
- name: ensure required packages are installed
apt: pkg={{ item }} state=present
with_items:
- package_1
- package_2
sudo: yes
When user defines --tags "second"
in a command line I want only package_2
to be installed.
Is it possible to do with tags
expression or any other ways to get desired behaviour?
I don't believe this is possible. The yum module (which I imagine is similar to apt) states:
You would need to split the command into two seperate package tasks with tag "second" on the package_2 task.
EDIT
See below of an example of iterating a collection with a when condition so it only prints the second item with the correct tag. Hopefully this helps.