Creating multiple times the same role, but with different items

Reading your question again, I noticed you did actually not mention it has to be some kind of loop. Maybe applying 3 times the same role with different parameters suits your needs:

- hosts: localhost
  connection: local

  roles :

    - role: vagrant
      index: 1
      ip: 192.168.222.1
      name: mongo1
      user: nicorama

    - role: vagrant
      index: 2,
      ip: 192.168.222.2
      name: mongo2
      user: nicorama

    - role: vagrant
      index: 3
      ip: 192.168.222.3
      name: mongo3
      user: nicorama

Then in your role you can use the vars index, ip etc.


I know this is an ancient question, but you can now use loop with the newer include_role syntax:

- hosts: localhost
  connection: local

  tasks:
    - include_role: 
        name: vagrant
      vars:
        index: "{{ vagrant_vars.index }}"
        ip: "{{ vagrant_vars.ip }}"
        name: "{{ vagrant_vars.name }}"
        user: "{{ vagrant_vars.user }}"
      loop:
        - {index: 1, ip: 192.168.222.1, name: mongo1, user: nicorama }
        - {index: 2, ip: 192.168.222.2, name: mongo2, user: nicorama }
        - {index: 3, ip: 192.168.222.3, name: mongo3, user: nicorama }
      loop_control: 
        loop_var: vagrant_vars