How to specify Ansible role to play

Problem:
When run Ansible roles in a host, it will execute all roles assigned to this host. Can I run selected roles, instead of all?

The current workaround i have is to remove unwanted roles out of the host before submitting the job. but this is hard to manage.

Also, i have to do this one host by one host. In the All Hosts page, seems no option to do bulk update of role assignment. Not sure if there is any API can achieve this.

Foreman and Proxy versions:
Foreman: 1.22

Foreman and Proxy plugin versions:
foreman_ansible: 3.0.2
foreman_remote_execution: 1.8.0

If you mean in a way that you would assign roles to a host and then selected a subset of those to be run, then no. What you can do is create a custom template which would take a list of roles as an input and apply them.

About the batch assignment, I don’t think there’s a way to do that. You could assign your roles to hostgroups and your hosts to the hostgroups. Then by changing the roles in the groups you could change the roles for multiple hosts at once. But you’d lose a bit of flexibility by doing so.

Good advice and Thanks @aruzicka

With the customizable template, i think there is no need to think too much about the role batch assignment for now.

But when the day I will have hundreds or even thousands of hosts, it is really a physical work to assign roles to hosts one by one.