how to run a particular task on specific host in ansible


my inventory file’s contents –

in my tasks file which is in common role i.e. it will run on both hosts but I want to run a following task on host webservers not in dbservers which is defined in inventory file

is when module helpful or there is any other way? How could I do this ?


If you want to run your role on all hosts but only a single task limited to the webservers group, then – like you already suggested – when is your friend.

You could define a condition like:

Leave a Reply