Ansible role help for executing tags

Hello
Newbie , trying to understand how a single task in role can be executed ?
Is it possible in tasks/main.yml of roles to use ansible.tags and only execute ansible-playbook <role.yml> -i --tasks= <task.name> ?

No, not exactly. --tasks is not an option on ansible-playbook. (And -i will want a parameter, but ignoring that…)

However, you can tag a task (or a play if you have multiple plays in your playbook), and then run only the task(s)/play(s) with that tag with

ansible-playbook ... --tags=mytag

See the tags docs for lots of examples.

[EDIT: Forget what I said about tags on plays. It does more than just tag a play; it also implicitly tags all the tasks in that play (and probably statically loaded with it). Stick with the tasks bit at first.]

2 Likes