In ansible how to select specific tasks in a role according to the playbook or a more general parameter?
Different approaches can be useful for different setups. You can use tags in some cases, or conditional includes (as you describe) in other cases.


  On the other hand, it generates quite a payload of “skipped” tasks in ansible logs, which raises a red sign to me.


You should get familiar with difference between static and dynamic includes in Ansible.

So if you use static includes, you will get a lot of skipped tasks, because every task in every file is added to execution queue but most of them are skipped because of when statement.

tasks/main.yml of your role with actions install/uninstall:

- include: install.yml
  when: action == 'install'
- include: uninstall.yml
  when: action == 'uninstall'


But if you use dynamic includes, only required tasks are added to execution queue and skipped message is displayed for skipped includes.

tasks/main.yml:

- include_tasks: install.yml
  when: action == 'install'
- include_tasks: uninstall.yml
  when: action == 'uninstall'


More on that, you can avoid skipped message altogether like this:

tasks/main.yml:

- include_tasks: '{{ action }}.yml'


The drawback of dynamic includes is that you can't do complete static analysis of your playbook (like syntax checks, etc.) because many things are know only in runtime.