Need help with tags

Hi,

I’d like to use tags to select tasks I launch.
I found documentations about how to limit playbook, role… execution to the tagged tasks l choose from adhoc command (-t option).

But I need to do the same from another playbook… and I can’t find anything about that

ex :
extract from the main.yml from role “myrole” :

There is no capability to limit tags from within a playbook. Tags can only be limited from the CLI via -t/–tags

Thanks Matt for your quick answer… Even if it doesn’t arrange me… :wink:
It’s weird this is not possible. I’m surprised. I guess I’m not the first one to consider doing this. Is there a reason why ?
Did you (or someone else) hear about a “trick” to get a similar behaviour using something else ?

Regards

I finally found a “trick” that made it for me :
Every task in the main.yml from “myrole” are conditioned with a different value for a variable myowntags
ex:
when: myowntags == “fst-openshot”

Then, in a taskfile or playbook, I can select the tasks I want with something like :

  • name: test
    include_role:
    name: myrole
    vars:
    myowntags: “fst-openshot”

As this role is only dedicated to pick up some tasks when needed (not applied to any group as itself), it makes it for me.

Every task in the main.yml from "myrole" are conditioned with a different
value for a variable myowntags
ex:
when: myowntags == "fst-openshot"

Then, in a taskfile or playbook, I can select the tasks I want with
something like :
- name: test
  include_role:
    name: myrole
      vars:
        myowntags: "fst-openshot"

As this role is only dedicated to pick up some tasks when needed (not
applied to any group as itself), it makes it for me.

Next option would be to fragment main.yml and put the tasks into
the separate files, e.g

  > cat main.yml
  - import_tasks: tasks01.yml
  - import_tasks: tasks02.yml
    ...

This would keep the original functionality untouched. Now, create
files with the logical blocks you'd like to use, e.g.

  shell: cat fst-openshot.yml
  - import_tasks: tasks07.yml
  - import_tasks: tasks25.yml
  - import_tasks: tasks33.yml

Then, it would be possible to include such blocks selectively, e.g.

  - name: test
    include_role:
      name: myrole
      tasks_from: "{{ myowntags }}.yml"

Thanks Vladimir
I didn’t heard about tasks_from.
I’ll test it too

We've seen this requested several times, but it is normally an
indicator of people making plays/roles way too big.

So we recommend actually splitting the playbook/roles into the more
manageable units instead of implementing this kind of functionality or
using a workaround via conditionals.