In Ansible, i want to trigger selected tasks based on hosts.
My inventory:
[appserver]
ip1
ip2
[webserver]
ip3
ip4
And my main.yml file will be like this
- name : Playbook
hosts: all
user: username
become: yes
gather_facts: True
tasks:
- name: Task 1
replace:
path: "somepath"
regexp: "{{ oldvalue }}"
replace: "{{ newvalue }}"
backup: yes
- name: Task 2
replace:
path: "somepath"
regexp: "{{ oldvalue }}"
replace: "{{ newvalue }}"
backup: yes
How do I run this particular task1 on appserver group and task2 on webserver group. Is there any best way to achieve this without using ansible tags?