Include Tasks of Role By Tag Or Filter In Ansible Playbook

Viewed 662

How can I specify only a subset of the tasks of a role for inclusion?

Say, I want to include the tasks from the role foobar, but only the ones tagged by baz:

  tasks:
  - import_role:
      name: foobar
    tags:
      - baz

The above does not work, because Ansible will interpret this as "only include foobar if tag baz is specified" instead of "only include tasks with the tag baz"

Is there some mechanism that allows to specify only a subset of role tasks for inclusion?

1 Answers

Q: "Is there some mechanism that allows specifying only a subset of role tasks for inclusion?"

A: The only option is the parameter tasks_from. As you have already found out the selection by tags is available from the command line (--tags) only.

Related