how to run a particular task on specific host in ansible

前端 未结 3 983
遥遥无期
遥遥无期 2021-01-07 16:40

my inventory file\'s contents -

[webservers]
x.x.x.x ansible_ssh_user=ubuntu

[dbservers]
x.x.x.x ansible_ssh_user=ubuntu

in my tasks file

3条回答
  •  不知归路
    2021-01-07 17:26

    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:

    when: inventory_hostname in groups['webservers']
    

提交回复
热议问题