--- - hosts: webserver gather_facts: yes become: yes tasks: - name: Install apache apt: pkg=apache2 state=latest notify: - restart apache2 - name: Enable apache2 during boot service: name=apache2 state=started enabled=yes handlers: - name: restart apache2 service: name=apache2 state=restarted - hosts: loadbalancer become: yes tasks: - name: Install nginx apt: pkg=nginx state=latest notify: - restart nginx - name: Enable nginx during boot service: name=nginx state=started enabled=yes handlers: - name: restart nginx service: name=nginx state=restarted