--- - hosts: all become: True tasks: - name: Install common packages on all hosts package: name: "{{ packages_common }}" state: present - hosts: all become: True tasks: - name: Install extra packages if listed package: name: "{{ packages_extra | default([]) }}" state: present